代码区项目交易流程

Downloading a file from Autodesk A360 to a shopping cart in NodeJS


I am using the Forge data management API to access my A360 files and aim to translate them into the SVF format so that I can view them in my viewer. So far I have been able to reach the desired item using the ForgeDataManagement.ItemsApi, but I don't know what to do with the item to upload it to the bucket in my application.

From the documentation it seems like uploadObject is the way to go ( https://github.com/Autodesk-Forge/forge.oss-js/blob/master/docs/ObjectsApi.md#uploadObject ), but I don't know exactly how to make this function work.

var dmClient = ForgeDataManagement.ApiClient.instance; var dmOAuth = dmClient.authentications ['oauth2_access_code']; dmOAuth.accessToken = tokenSession.getTokenInternal(); var itemsApi = new ForgeDataManagement.ItemsApi(); fileLocation = decodeURIComponent(fileLocation); var params = fileLocation.split('/'); var projectId = params[params.length - 3]; var resourceId = params[params.length - 1]; itemsApi.getItemVersions(projectId, resourceId) .then (function(itemVersions) { if (itemVersions == null || itemVersions.data.length == 0) return; // Use the latest version of the item (file). var item = itemVersions.data[0]; var contentLength = item.attributes.storageSize; var body = new ForgeOSS.InputStream(); // var body = item; // Using the item directly does not seem to work. // var stream = fs.createReadStream(...) // Should I create a stream object lik suggested in the documention? objectsAPI.uploadObject(ossBucketKey, ossObjectName, contentLength, body, {}, function(err, data, response) { if (err) { console.error(err); } else { console.log('API called successfully. Returned data: ' + data); //To be continued... }

I hope someone can help me out!

My current data:

ossObjectName = "https://developer.api.autodesk.com/data/v1/projects/"myProject"/items/urn:"myFile".dwfx"; ossBucketKey = "some random string based on my username and id";

Regards, torjuss

When using the DataManagement API, you can either work with

2 legged oAuth (client_credentials) and access OSS' buckets and objects, or 3 legged (authorization_code) and access a user' Hubs, Projects, Folders, Items, and Revisions

When using 3 legged, you do access someones content on A360, or BIM360 and these files are automatically translated by the system, so you do not need to translate them again, not to transfer them on a 2 legged application bucket. The only thing you need to do it is get the manifest of the Item or its revision and use the URN to see it in the viewer.

Checkout an example here: https://developer.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/

you'll see something like Examples: Successful Retrieval of a Specific Version (200)

curl -X GET -H "Authorization: Bearer kEnG562yz5bhE9igXf2YTcZ2bu0z" "https://developer.api.autodesk.com/data/v1/projects/a.45637/items/urn%3Aadsk.wipprod%3Adm.lineage%3AhC6k4hndRWaeIVhIjvHu8w" { "data": { "relationships": { "derivatives": { "meta": { "link": { "href": "/modelderivative/v2/designdata/dXJuOmFkc2sud2lwcWE6ZnMuZmlsZTp2Zi50X3hodWwwYVFkbWhhN2FBaVBuXzlnP3ZlcnNpb249MQ/manifest" } },

Now, to answer teh other question about upload, I got an example available here: https://github.com/Autodesk-Forge/forge.commandline-nodejs/blob/master/forge-cb.js#L295 . I copied the relevant code here for everyone to see how to use it:

fs.stat (file, function (err, stats) { var size =stats.size ; var readStream =fs.createReadStream (file) ; ossObjects.uploadObject (bucketKey, fileKey, size, readStream, {}, function (error, data, response) { ... }) ; }) ;

Just remember that ossObjects is for 2 legged, where as Items, Versions are 3 legged.

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

点击收藏

LAST Hide the output of echo json_encode socket.io emit data will disconnect the client NEXT