如何使用Autodesk Model Forge API下载SVG / SVF以供离线查看

时间:2017-02-02 18:42:17

标签: autodesk autodesk-forge autodesk-viewer autodesk-model-derivative

我能够完成上传Revit文件并在查看器中翻译和加载的所有步骤。我现在正在尝试下载已翻译的SVG / SVF以供离线查看。我找到了对以下端点的引用并用它测试了它:

function download(){
var uri = 'https://developer.api.autodesk.com/derivativeservice/v2/derivatives/<<urn>>' ;
var authorizationHeader = 'Bearer <<token>>'

request.get(
    {
        url: uri,    
        headers:
        {
            'Authorization': authorizationHeader,
            'Accept-Encoding': 'gzip, deflate'
        },
    },

    function(error, response, body){ 
        if(!error){
            console.log(body); 
        }else{
            console.log(error);
        }
    });
}

API返回:
{“diagnostic”:“Derivative api仅支持adsk.viewing&amp; adsk.objects urn”}

2 个答案:

答案 0 :(得分:3)

urn应该是url编码的,而不是base64编码的。

答案 1 :(得分:2)

如果您希望获取所有必需的文件以供离线查看,则有几个步骤。首先检查提取downloadBubble中的project方法(node.js):

this.downloadBubble =function (urn, outPath) {
    var self =this ;
    self._outPath =outPath ;
    return (new Promise (function (fulfill, reject) {
        self._progress.msg ='Downloading manifest' ;
        self.getManifest (urn)
            .then (function (bubble) {
                //utils.writeFile (outPath + 'bubble.json', bubble) ;
                self._progress.msg ='Listing all derivative files' ;
                self.listAllDerivativeFiles (bubble.body, function (error, result) {
                    self._progress._filesToFetch =result.list.length ;
                    console.log ('Number of files to fetch:', self._progress._filesToFetch) ;
                    self._progress._estimatedSize =0 | (result.totalSize / (1024 * 1024)) ;
                    console.log ('Estimated download size:', self._progress._estimatedSize, 'MB') ;

                    //self.fixFlatBubbles (result) ;
                    //self.fixFusionBubbles (result) ;

                    self._progress.msg ='Downloading derivative files' ;
                    self.downloadAllDerivativeFiles (result.list, self._outPath, function (failed, succeeded) {
                        //if ( ++self._done == 1 /*2*/ )
                        //  return ;
                        self.failed =failed ;
                        self.succeeded =succeeded ;
                        fulfill (self) ;
                    }) ;
                }) ;
            })
            .catch (function (err) {
                console.error ('Error:', err.message) ;
                self._errors.push (err.message) ;
                reject (self) ;
            })
        ;
    })) ;
} ;

https://extract.autodesk.io

现场测试