Autodesk Forge-使用curl下载文件 [英] Autodesk Forge - download a file using curl

查看:145
本文介绍了Autodesk Forge-使用curl下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,通过python脚本将.sldprt转换为.obj文件.我正在关注教程.在最后一部分中,我必须将翻译后的文件下载到本地计算机上.下载文件的命令行命令如下(步骤5)

I am working on a project to convert .sldprt to .obj file through a python script. I am following this tutorial. In the last part, I have to download the translated file to my local machine. The command-line command to download the file is as follows (STEP 5)

sudo curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$SURN/manifest/$OURN" -o $OUTFILE

其中$ TOKEN是访问令牌,$ SURN是上载文件URN,OURN是输出文件URL,$ OUTFILE是输出文件名(在这种情况下为output.obj)

where $TOKEN is the access token, $SURN is the uploaded file URN and the OURN is the output file URL and $OUTFILE is the output file name (output.obj in this case)

我意识到执行上述命令会给我HTTP 400错误(错误请求).错误的屏幕快照如下所示.

I realized that executing the above command gives me HTTP 400 error (bad request). A screenshot of the error is shown below.

几天前,我确实执行了相同的命令并正确下载了文件,但是,我不记得有什么不同.有人可以指导我请求格式有什么问题吗?

A couple of days ago, I did execute the same command and downloaded the file appropriately, however, I don't remember what was different. Can someone guide me whats wrong with the request format?

我认为与无效的令牌/SURN/OURN等无关,因为在那种情况下,我不会收到无效的消息格式错误.

I believe it has nothing to do with invalid TOKEN/SURN/OURN etc because in that case, I would not have got the invalid message format error.

推荐答案

要从OSS下载对象,您需要使用以下命令:

To download an object from OSS you need to use a command like this:

curl -X GET https://developer.api.autodesk.com/oss/v2/buckets/mybucket/objects/myobjectref -H "Authorization: $bearer" -o myfile.ext

要获取对象清单及其所有派生类,您需要调用:

To get the object manifest and all it derivatives you need to call:

curl -X GET https://developer.api.autodesk.com/modelderivative/v2/designdata/$urn/manifest -H "Authorization: $bearer"

如果清单不存在,则此清单请求应返回一个空响应和404状态代码.添加-v选项以查看404错误. 如果衍生工具不存在,则.../$ urn/manifest/$ derivativeUrn请求应返回一个空响应和一个400状态码(不是有效请求).

This manifest request should return you an empty response, and a 404 status code, if the manifest does not exists. Add the -v option to see the 404 error. The .../$urn/manifest/$derivativeUrn request should return an empty response and a 400 status code (not a valid request) if the derivative does not exist.

现在要完成我的回答,清单是一个JSON响应,它描述了对象如何转换为各种派生对象以及与对象(所有派生的种子文件)相对应的提取内容.

Now to complete my answer the manifest is a JSON response which describes how the object was translated to various derivatives and what is available for extraction vs the object which is the seed file of all derivatives.

现在,如果要下载衍生版本之一(例如OBJ),则需要获取衍生版本URN(指向OBJ翻译的版本)并调用:

Now if you want to download one of the derivatives (for example an OBJ), you need to get the derivative URN (the one pointing the OBJ translation) and call:

curl -X GET https://developer.api.autodesk.com/modelderivative/v2/designdata/$urn/manifest/$derivativeUrn -H "Authorization: $bearer"

$ urn指向种子文件,$ derivativeUrn指向您可以在清单文件中找到的obj衍生物.

$urn points to the seed file, $derivativeUrn points to the obj derivative that you can find in the manifest file.

我刚刚在上面的屏幕截图中注意到,您使用的是base64编码的urn容器,而不是安全的base64编码的urn容器.这实际上是不正确的,因为base64编码的字符串可以包含诸如'+/='之类的字符,这在HTTP请求中具有不同的含义. "+"表示空格,"/"表示动词分隔符,"="表示变量赋值. 请在上面的请求中删除结尾的'=',它应该可以正常工作.

Edits: I just noticed on your screenshot above that you are using a base64 encoded urn vs a safe base64 encoded urn. This is actually not correct since a base64 encoded string can contain characters like '+ / = ' which has a different meaning in an HTTP request. '+' would mean space, '/' would mean a verb separator, and '=' a variable assignment. Please remove the trailing '=' in your request above and it should work fine.

这篇关于Autodesk Forge-使用curl下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆