我使用Forge數據管理API訪問我的A360文件,並將其轉換爲SVF格式,以便我可以在查看器中查看它們。到目前爲止,我已經能夠使用ForgeDataManagement.ItemsApi訪問所需的項目,但我不知道如何處理項目以將其上傳到應用程序中的存儲桶。將文件從Autodesk A360上傳到NodeJS中的存儲桶
從文檔看來,uploadObject是要走的路(https://github.com/Autodesk-Forge/forge.oss-js/blob/master/docs/ObjectsApi.md#uploadObject),但我不知道如何使此功能工作。
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...
}
我希望有人能幫助我!
我現在的數據:
ossObjectName = "https://developer.api.autodesk.com/data/v1/projects/"myProject"/items/urn:"myFile".dwfx";
ossBucketKey = "some random string based on my username and id";
問候, torjuss
謝謝你的回答,cyrille!直接使用A360文件而不轉移到應用程序存儲區是有意義的。然而;當我現在嘗試啓動我的查看器並加載文檔時,我會得到401未授權狀態,無論我使用2或3多方認證(不太確定使用哪一個)。我使用以下方法: Autodesk.Viewing。Document.load(documentId,oauth3legtoken,function(doc){...}); 並獲取以下HTTP狀態: https://developer.api.autodesk.com/oss-ext/v1/acmsessions 401(未授權) – torjuss
我發現下面的帖子看起來像是與此問題有關。你知道它是否已經修復,還是必須使用Philippe Leefsma建議的替代方法? http://stackoverflow.com/questions/37835178/creating-a-viewer-application-with-an-urn-from-autodesk-a360/38328133#38328133 – torjuss