未加星标

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

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二04 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

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教程

代码区博客精选文章
分页:12
转载请注明
本文标题:Downloading a file from Autodesk A360 to a shopping cart in NodeJS
本站链接:https://www.codesec.net/view/628146.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(34)