0

I've uploaded file to oss and have object id, if bucket object is not yet translated then how to check derivatives info. with object id?

bim2016
  • 105
  • 1
  • 10

1 Answers1

1

It's straightforward, just base64 encode your objectId, then call GET {urn}/manifest. If it returns a 404 http status code, then it means this URN hasn't got translated.

If your file is stored on BIM360/ACC, you will need to get derivative URN from the file's version tip. Please follow this tutorial, but find relationships.data.derivatives.data.id instead for the URN like the below for example.

https://forge.autodesk.com/en/docs/bim360/v1/tutorials/document-management/download-document/#step-4-find-the-storage-object-id-for-the-file

"derivatives": {
    "data": {
        "type": "derivatives",
        "id": "dXJuOmFkc2sud2lwcHJvZDpmcy5maWxlOnZmLkVueWtrU3FjU0lPVTVYMGhRdy1mQUM_dmVyc2lvbj0x"
    },
    // ...
},

Node.js code sample tested with yiskang/forge-viewmodels-nodejs-svf2

const {
    DerivativesApi
} = require('forge-apis');

const { getClient, getPublicToken } = require('./routes/common/oauth');

const derivativeApi = new DerivativesApi();

const urn = 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvdGVzdC5ydnQ';

getPublicToken().then(accessToken => {
    derivativeApi.getManifest(urn, {}, null, accessToken).then(function (res) {
        console.log(res.statusCode, res.statusMessage);
    },
    function (err) {
        // When the urn hasn't got translated, it goes here
        console.error('error', err.statusCode, err.statusMessage);
        // if you want to redire page to some where, write your codes here
    });
}, function (err) {
    console.error(err);
});

ref: https://stackoverflow.com/a/70664111/7745569

Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • right, didn't explore derivatives in depth yet, thanks Eason and have a great weekend – bim2016 Feb 25 '22 at 06:30
  • i tested in JS, seems not working, see below code FYI, var urn = item.objectId.toBase64(); var status = null; var derivatives = new ForgeSDK.DerivativesApi() .getManifest(urn, {}, null, tokenInternal) .catch(function (err) { console.log(err); }) .then((d) => { return d.statusCode; }); const checkStatus = async () => { status = await derivatives; console.log(status); }; checkStatus(); if (status === 404) return; – bim2016 Feb 25 '22 at 19:07
  • well, it's promise and/or async related issue, above code is inside a promise, since getManifest is also a promise, need to get the result before continuing i.e. @ last line of code "if (status === 404) return;", how to achieve it? in short, inside promise A -> first get result of promise B ->then use that result to continue in promise A – bim2016 Feb 26 '22 at 03:19
  • hi Eason, maybe it's not promise and/or async related issue, 404 error will be generated by server and sent to client, right? so how to use it directly in server, what i want to achieve is to check if already uploaded bucket object is translated, if not then do translation. – bim2016 Feb 26 '22 at 18:03
  • you cannot simply redirect to another route after catch 404 error, right? – bim2016 Feb 26 '22 at 18:22
  • 1
    It sounds like a node.js routing issue, rather than Forge... I added my test case above. You will need to write your redirect logic in where I put comments. – Eason Kang Mar 03 '22 at 09:46
  • thanks Eason, I did try your method (added redirect @ 404), not working well, I guess part of reason is that code segment is nested inside forEach loop which is also nested in another promise, in fact, I'm referring to GitHub sample of "forge-view.googledrive.models" and try to add checking Derivatives so alreadyTranslated is really the case. – bim2016 Mar 04 '22 at 01:57