0

I have to upload a file from a server to docs management, but i have a problem at upload file step. For information, i do my script with Dynamics NAV.

Before doing the upload from Dynamics NAV, i tried with Git Bash and cURL commands : it works.

This is the permissions that i have : see here

This is all steps and what i can do:

  • Find HubID of my folder i want to upload (DONE)
  • Create storage location (DONE)
  • Upload file (FAIL)
  • Create first version.

When i do the upload step, i have an error 401 : Forbidden but i don't know where i'm suppose to go for set good permissions.

This is the cURL command :

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"

So after seeing this, i don't need to set special permissions for upload a file.

This this my Dynamics Nav code :

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);

With this i need a specific permissions ...

Some suggestions ?

2 Answers2

0

The problem should be related to your access_token. Before everything, you need to get your 3-legged access token by the 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/.

Hope it helps.

Zhong Wu
  • 1,721
  • 1
  • 8
  • 9
  • i use a 3 legged token. This is my scope parameters : scope=account:read account:write data:read data:write data:create bucket:read bucket:create – Hervé PFAUWADEL May 31 '18 at 13:21
0

I found the solution.

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);