Search code examples
autodesk-forgeautodesk-bim360

how to check if bucket object is already translated


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?


Solution

  • 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