我正在尝试在上传后转换对象,但我一直收到400 Bad Request
错误。
这是我的代码的样子
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);
}
);
我的job
对象如下所示:
{
input:{
urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZDYyZGIwOTAtMGM0Ny0xMWU4LTlhMzYtN2JkMDZjZWRmMDU4L1Bhd24uc3Rs'
},
output: {
formats: [
type: "obj"
]
}
}
回复
{
statusCode: 400,
statusMessage: "Bad Request"
}
答案 0 :(得分:1)
我还有一个使用Forge NPM的教程来完成创建存储桶以上传文件并翻译它的整个过程。我认为您遇到问题的部分是上传部分
选中此https://github.com/jaimerosales/modelderivative-nodejs-tutorial/blob/master/uploader.js#L145
答案 1 :(得分:0)
您的有效负载不正确,它应如下所示:
{
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']
}
}
})
您需要执行其他API调用以检索模型GUID:有关详细信息,请参阅GET :urn/metadata