如何为FORGE API上传文件设置好的权限?

How to set good permissions for uploading file by FORGE API?

我必须从服务器上传一个文件到文档管理,但是我在上传文件这一步遇到了问题。有关信息,我使用 Dynamics NAV 编写脚本。

在从 Dynamics NAV 上传之前,我尝试使用 Git Bash 和 cURL 命令:它有效。

这是我拥有的权限: see here

这是所有步骤以及我能做什么:

当我执行上传步骤时,出现错误 401:禁止访问,但我不知道应该去哪里设置好的权限。

这是 cURL 命令:

curl -X PUT -H "Authorization: Bearer nq4dc0KRWeaaUnyIJA8aN0MIKi3j" 
    --data-binary '@\server\folder\subfolder\file.rvt' 
    "https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/2448af43-45f3-4b81-a8cf-38c69b03197b.rvt"

所以看到这个后,我不需要设置上传文件的特殊权限。

这是我的动态导航代码:

HttpWebRequestMgt.Initialize(STRSUBSTNO('https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/%1',Filename));
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('PUT');
HttpWebRequestMgt.SetContentType('application/octet-stream');
HttpWebRequestMgt.AddHeader('Authorization','Bearer ' + Token);

FileManagement.BLOBImportFromServerFile(TempBlob,ServerFolder+'\'+Filename);

HttpWebRequestMgt.AddBodyBlob(TempBlob);

CLEAR(TempBlob);
TempBlob.Blob.CREATEINSTREAM(ResponseInStream);

HttpWebRequestMgt.GetResponse(ResponseInStream,HttpStatusCode,ResponseHeaders);
ResponseInStream.READTEXT(ResponseText);

CLEAR(HttpWebRequestMgt);
CLEAR(TempBlob);

有了这个我需要一个特定的权限...

一些建议?

问题应该与您的access_token有关。在一切之前,您需要通过 API https://developer.autodesk.com/en/docs/oauth/v2/tutorials/get-3-legged-token/, to upload the file, please make sure to have the scope of "data:create" or "data:write scope", for the details, refer the page https://developer.autodesk.com/en/docs/data/v2/tutorials/upload-file/ 获取您的三足访问令牌。

希望对您有所帮助。

我找到了解决方案。

BIM360Setup.GET;
SalespersonPurchaser.GET(BIM360Setup."Default Job Admin");

IF Token = '' THEN 
  Token := Get3LeggedToken;

StorageID := COPYSTR(FileURNID,STRPOS(FileURNID,'/') + 1);//***

HttpWebRequestMgt.Initialize(STRSUBSTNO('https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/%1',StorageID));
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetMethod('PUT');
HttpWebRequestMgt.SetContentType('application/x-www-form-urlencoded');
HttpWebRequestMgt.AddHeader('Authorization','Bearer ' + Token);
HttpWebRequestMgt.SetReturnType('*/*');

FileManagement.BLOBImportFromServerFile(TempBlob,ServerFolder+'\'+Filename);
HttpWebRequestMgt.AddBodyBlob(TempBlob);


CLEAR(TempBlob);
TempBlob.Blob.CREATEINSTREAM(ResponseInStream);

HttpWebRequestMgt.GetResponse(ResponseInStream,HttpStatusCode,ResponseHeaders);

ResponseText := TempBlob.ReadAsText('',TEXTENCODING::UTF8);

CLEAR(HttpWebRequestMgt);
CLEAR(TempBlob);