问题
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
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)
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?
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.
回答1:
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"
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.
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.
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 points to the seed file, $derivativeUrn points to the obj derivative that you can find in the manifest file.
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.
来源:https://stackoverflow.com/questions/56154777/autodesk-forge-download-a-file-using-curl