I am trying to translate an object after uploading it but I keep getting 400 Bad Request error.
I am using the forge-api-nodejs-client
here is how my code looks like
var base64 = require('js-base64').Base64;
objectsApi.uploadObject(
bucket.bucketKey,
file.originalname,
file.size,
file.buffer,
{},
oAuth2TwoLegged,
credentials
)
.then(
response => {
const objectDetails = response.body;
// objectId => urn:adsk.objects:os.object:d62db090-0c47-11e8-9a36-7bd06cedf058/Pawn.stl
const job = {
input: {
urn: base64.encode(objectDetails.objectId)
},
output: {
formats: [
{
type: "obj"
}
]
}
};
derivativesApi
.translate(job, {}, oAuth2TwoLegged, credentials)
.then(
data => {
res.send(data);
},
err => {
// it fails here with 400 status error
res.send(err);
}
);
},
err => {
res.send(err);
}
);
my job object looks like this:
{
input:{
urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZDYyZGIwOTAtMGM0Ny0xMWU4LTlhMzYtN2JkMDZjZWRmMDU4L1Bhd24uc3Rs'
},
output: {
formats: [
type: "obj"
]
}
}
the response
{
statusCode: 400,
statusMessage: "Bad Request"
}
I have also a tutorial using the Forge NPM to do the whole process of creating bucket to upload file and translate it. I think the part you are having problems with is the uploading part
Check this https://github.com/jaimerosales/modelderivative-nodejs-tutorial/blob/master/uploader.js#L145
Your payload is incorrect, it should look like below:
{
input: {
urn: "...place your design url here ..."
},
output:{
force: false, // true if you want to force regenerate the obj, after new model upload for ex (optional)
formats: [{
type: 'obj',
advanced: {
modelGuid: "...", // model GUID, required
objectIds: [-1] // array of dbIds to export, required. Pass [-1] to export full model, or specific dbIds ex: [49, 56, ...]
}
}],
destination: {
region: 'us' // default, optional can be ['us', 'emea']
}
}
})
You need to perform additional API call to retrieve the model GUID: see GET :urn/metadata for more details
Related
I'm trying to upload file to BIM360DOCS. Referring this I could successfully upload the first version of file, but I'm facing issues while updating the version. For updating version of file, I created a storage location, uploaded a file to the storage location, But I try to update the version, I'm getting 400 in response.
I'm referring this method.
const body: CreateVersion = {
jsonapi: { version: "1.0" },
data: {
type: "versions",
attributes: {
name: fileName,
extension: {
type: versions:autodesk.bim360:File" // "versions:autodesk.core:File",
version: "1.0",
schema: {
href: ""
}
}
},
relationships: {
item: {
data: {
type: "items",
id: folderId
}
},
storage: {
data: {
type: "objects",
id: objectId
}
}
}
}
}
const version = await new VersionsApi().postVersion(projectId, body, internalTokenClient, internalToken)
But this gives me 400 ERROR saying
errors: [
{
id: '92######-####-####-####-######c98bb5',
status: '400',
code: 'BAD_INPUT',
title: 'One or more input values in the request were bad',
detail: 'The object is not the correct type.'
}
]
Whereas I'm passing 'projectId', 'internalTokenClient', 'internalToken' correctly, as same for creating first version of file. Is there any issue in my payload?
I've also tried it in postman, gives same error. I've added postman screenshot for reference.
I was passing "folderId" in relationships instead of relationship lineage.
Tried passing lineage from previous version response worked properly.
const body: CreateVersion = {
jsonapi: { version: "1.0" },
data: {
type: "versions",
attributes: {
name: fileName,
extension: {
type: versions:autodesk.bim360:File"
version: "1.0",
schema: {
href: ""
}
}
},
relationships: {
item: {
data: {
type: "items",
id: <relationship lineage from previous version>
}
},
storage: {
data: {
type: "objects",
id: objectId
}
}
}
}
}
const version = await new VersionsApi().postVersion(projectId, body, internalTokenClient, internalToken)
I'm really sure about, that this question is answered multiple times in here. But I can't find them/don't knwo which terms to search for.
I've got a JSON-file looking like that:
{
"pages": [{
"displayname": "PageA",
"url": "http://google.de",
"icon": "iconZ"
},
{
"displayname": "PageB",
"url": "http://www.pageb.co.uk",
"icon": "iconY"
}
],
"icons": [{
"alias": "iconZ",
"filename": "iconZ.svg"
},
{
"alias": "iconY",
"filename": "iconY.svg"
}
]
}
Now I'm using the HttpClient (here called httpService) to get the data from the file.
this.httpService.get('./assets/pageconfig.json').subscribe(
data => {
this.arrAdress = data as string[];
},
(err: HttpErrorResponse) => {
console.log(err.message);
}
);
I want to use the content of pages in my ngFor in the Frontend and I want to get an array of the icon-content for use in the Backend. How can I select/split the data by using the properties.
Thanks for your help
Elias
Considering your pageconfig.json is used in both front and backend, and that you just need the "pages" attribute in your angular app, you may get it this way:
this.httpService.get('./assets/pageconfig.json').subscribe(
data => {
this.arrAdress = data.pages;
},
(err: HttpErrorResponse) => {
console.log(err.message);
}
);
You don't need to cast the data type.
You could also use the rxjs observable map chaining to parse your data and get only what interests you:
import { map } from 'rxjs/operators';
this.httpService.get('./assets/pageconfig.json')
.pipe(map(data => data.pages))
.subscribe(pages=> {
this.arrAdress = pages;
}.catch((err: HttpErrorResponse) => {
console.log(err.message);
});
I hope this is what you were looking for.
Need to remove string[], instead use Array of object or any.
this.httpService.get('./assets/pageconfig.json').subscribe(
data => {
this.arrAdress = data;
},
(err: HttpErrorResponse) => {
console.log(err.message);
}
);
sendData(icon){
const matched = this.arrAdress.icons.filter(iconObj => iconObj.alias === icon);
console.log(matched);
}
**Template:**
<div *ngFor="let adress of arrAdress?.pages;" (click)="sendData(adress.icon)">
<span>{{adress.displayname}}</span>
</div>
You have two solutions here to solve this issue
Suppose httpClient.Delete() option returns back you an observable object with employeeId as property in it.
Solution 1 (example)
Create an local variable and assign data to it using let statement (e.g. let response: any = data;).
delete(employee: any) {
this.employeeService.deleteEmployee(employee.id)
.subscribe(
data => {
let response: any = data;
// now you can use response.employeeId
},
(error) => {
console.log(error)
},
() => {
console.log("The operation has been completed")
}
);
}
Solution 2 (example)
Assign type any (e.g. (data : any) to received response
delete(employee: any) {
this.employeeService.deleteEmployee(employee.id)
.subscribe(
(data: any) => {
// now you can use data.employeeId
},
(error) => {
console.log(error)
},
() => {
console.log("The operation has been completed")
}
);
}
I'm new using Django and Shield UI, what I'm trying to do is trying to get data for a shieldGrid, making a request to get remote data from the server. I have the next code.
this is my .js
$("#id_table_diagnosticos").shieldGrid({
dataSource: {
remote: {
read: {
url: "/atender/ListadoDiagnosticos/",
dataType: "json",
operations: ["sort", "skip", "take"],
data: function (params) {
var odataParams = {};
if (params.sort && params.sort.length) {
odataParams["$orderby"] = window.orderFields[params.sort[0].path].path + (params.sort[0].desc ? " desc" : "");
}
if (params.skip != null) {
odataParams["skip"] = params.skip;
}
if (params.take != null) {
odataParams["top"] = params.take;
}
return odataParams;
}
}
},
schema: {
data: "fields",
total: function (result) {
return result["odata.count"];
},
fields: window.orderFields = {
// "pk": { path: "pk" },
"descripcion": { path: "descripcion" },
"codigo": { path: "codigo" },
}
}
},
paging: true,
sorting: true,
columns: [
// { field: "pk", title: "ID", width: 80 },
{ field: "descripcion", title: "Descripción", width: 180 },
{ field: "codigo", title: "Código", width: 100 },
]
});
});
my model.py is
class ParametrosDiagnosticos(models.Model):
descripcion=models.CharField(max_length=1000)
codigo=models.CharField(max_length=100)
sexo=models.CharField(max_length=10,default='Ambos')
estado=models.CharField(max_length=100, default='Activo')
estado_logico=models.IntegerField(default=1)
and my view.py
def ListadoDiagnosticos(request):
if request.user.is_authenticated:
if request.method=='GET' and request.is_ajax():
objeto=ParametrosDiagnosticos.objects.all()
data = serializers.serialize('json', objeto, fields=('pk','descripcion','codigo'))
return JsonResponse(data,safe=False);
The request to server is doing ok, the problem is that when I return the data, I get the next error on the console of my browser.
shieldui-all.min.js:4 Uncaught TypeError: Cannot read property 'map' of undefined
at e (shieldui-all.min.js:4)
at init.fields (shieldui-all.min.js:5)
at init.process (shieldui-all.min.js:5)
at init._success (shieldui-all.min.js:5)
at e (bundled.js:2)
at Object.z.func.i.success (shieldui-all.min.js:4)
at j (bundled.js:2)
at Object.fireWith [as resolveWith] (bundled.js:2)
at x (bundled.js:5)
at XMLHttpRequest.b (bundled.js:5)
Thank you for your help.
Make sure your Grid's dataSource.schema is configured correctly. Documentation about it can be found here.
For example, if your data returned from the server contains a list of objects, you do not need to set its data property.
I have a json objectlike this
{"test": [{"href": "http://sdfsd.fd"}], "test2": [{"href": "http://sdfsd.fd"}]}
What I want to do is interate over all the links in the json, every likn point to another json object. then i want to get the json from the links, and replace the links with that json, so it comes like something like this:
{"test": {somejson}, "test2": {somejson}}
can this be done? right now I tried with a nested for loop, but the loop doesnøt care that the hhtp request hasn't got a response, before continuing in the loop, resulting in nothing is gonna be edited.
EDIT:
my code so far looks like this:
self.buildJSON = function(json) {
var links = [];
for(var post in json){
// console.log(json[post]['_links']);
for(var link in json[post]['_links']){
links.push(json[post]['_links'][link][0]['href']);
}
}
// var regex = /(http[s]?:\/\/)?([^\/\s]+)(.*)/
// for(link in links){
// var match = regex.exec(links[link]);
// var host = match[1]+match[2];
// var path = match[3];
// links[link] = {"host": host, "path": path};
// }
for(link in links){
request(links[link], function(error, response, body){
if (!error && response.statusCode == 200) {
links[link] = body;
}
})
}
console.log(links);
fs.writeFile(self.jsonfile, JSON.stringify(json));
the Json something like this ('_links' is part of a bigger json):
_links: {
self: [
{
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/posts/19"
}
],
collection: [
{
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/posts"
}
],
about: [
{
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/types/post"
}
],
author: [
{
embeddable: true,
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/users/1"
}
],
replies: [
{
embeddable: true,
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/comments?post=19"
}
],
version-history: [
{
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/posts/19/revisions"
}
],
wp:featuredmedia: [
{
embeddable: true,
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/media/130"
}
],
wp:attachment: [
{
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/media?parent=19"
}
],
wp:term: [
{
taxonomy: "category",
embeddable: true,
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/categories?post=19"
},
{
taxonomy: "post_tag",
embeddable: true,
href: "http://wordpress.sutdigselv.dk/wp-json/wp/v2/tags?post=19"
}
],
curies: [
{
name: "wp",
href: "https://api.w.org/{rel}",
templated: true
}
]
}
You need to parse your JSON first to get the links (maybe put them in an array). (hint: use JSON.stringify() and it becomes a string that you can parse)
Then iterate over each array element and send XHR requests (hint: XMLHttpRequest object). If you want to 'care' for each response, then use xhttp.open(method,url,false) and xhttp.send(). The 'false' will tell that Asynchronous mode is off and so it becomes synchronous. Beware of performance issues now since its synchronous. Read more here
Now create your own JSON object by storing the links in a string and using json.parse(string) to convert it to json
I'm trying to create mapping before uploading json data into elasticsearch.
I don't know how to implement mapping before uploading json data in sails.js
This is my bulkupload snippet
var body = [];
//row is json data
rows.forEach(function(row, id) {
body.push({ index: { _index: 'testindex', _type: 'testtype', _id: (id+1) } });
body.push(row);
})
client.bulk({
body: body
}, function (err, resp) {
if (err)
{
console.log(err);
return;
}
else
{
console.log("All Is Well");
}
});
I want to create mapping before data upload.can any one know how to create mapping in sails.
my Json object
[ { Name: 'paranthn', Age: '43', Address: 'trichy' },
{ Name: 'Arthick', Age: '23', Address: 'trichy' },
{ Name: 'vel', Age: '24', Address: 'trichy' } ]
Before making your client.bulk() call you first need to make another client.indices.putMapping() call like this in order to save the correct mapping for the data you're about to send via the bulk call:
client.indices.putMapping({
"index": "testindex",
"type": "testtype",
"body": {
"testtype": {
"properties": {
"your_int_field": {
"type": "integer"
},
"your_string_field": {
"type": "string"
},
"your_double_field": {
"type": "double"
},
// your other fields
}
}
}
}, function (err, response) {
// from this point on, if you don't get any error, you may call bulk.
});
Remember that all these calls are asynchronous, so be careful to only call bulk once putMapping has returned successfully.
Sounds like you need PutMapping.