2016-12-14 73 views
0

我使用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

回答

0

當使用數據管理API,您可以工作,

  • 2模式的OAuth(client_credentials)和訪問OSS」桶和對象,
  • 或3 legged(authorization_code)並訪問用戶的Hubs,Projects,Folders ,項目,並用3條腿的修訂

,你做訪問A360某人的內容,或BIM360而這些文件由系統自動翻譯,所以你不需要他們再翻譯,而不是將他們轉移在一個雙腿的應用桶上。您唯一需要做的就是獲取Item或其修訂版本的清單,並使用URN在查看器中查看它。

結帳這裏一個例子:https://developer.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-versions-version_id-GET/

,你會看到類似這樣的例子 :一個特定的版本(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" 
      } 
     }, 

成功檢索現在,回答有關上載德的其他問題,我這裏有一個例子: https://github.com/Autodesk-Forge/forge.commandline-nodejs/blob/master/forge-cb.js#L295。我在這裏複製的相關代碼給大家看如何使用它:

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) { 
     ... 
    }) ; 
}) ; 

只記得ossObjects是2條腿,其中的項目,版本是3條腿。

+0

謝謝你的回答,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

+0

我發現下面的帖子看起來像是與此問題有關。你知道它是否已經修復,還是必須使用Philippe Leefsma建議的替代方法? http://stackoverflow.com/questions/37835178/creating-a-viewer-application-with-an-urn-from-autodesk-a360/38328133#38328133 – torjuss

0

在Adam Nagy的支持下,我們想出瞭如何讓事情順利進行。簡單地說,我們必須使用3段OAuth來完成所有工作,因爲所有操作都涉及到來自A360賬戶的文檔。這包括訪問和顯示文件結構,將文檔翻譯成SVF,啓動查看器並將文檔加載到查看器中。

另外,我們在嘗試翻譯文檔時將錯誤的目標鎖定爲目標。 This post顯示了現在可以輕鬆完成,感謝Adam的信息!

相關問題