20 Aug 2020

Best practice for uploading and downloading files from BIM360 docs

Default blog image

After reading the BIM360 docs tutorial to upload and download a file, you may have assumed that the bucketKey was always 'wip.dm.prod' but while it was often the case, it is not meant to be always true. Therefore, never assume that value was never changing. So let's go back to step 4 in downloading a file - in the returned payload, you got a json response with this content:

...
"storage": {
   "data": {
       "type": "objects",
       "id": "urn:adsk.objects:os.object:wip.dm.prod/72d5e7e4-89a7-4cb9-9da0-2e2bbc61ca8e.dwg"
   },
   ...
}
...

What you want is to extract the bucketKey and objectKey from the the store.data.id, so you can continue using the OSS get object endpoint. To do this, you could use different techniques, but a regular expression can do this easily. You could use ^urn:adsk\.objects:os\.object:([-_.a-z0-9]{3,128})\/(.+)$ to extract both keys and validate their values.

You should be using the same technique for Upload (see step 5 in uploading a file) with OSS put object or resumable endpoints.

...
"data": {
  "type": "objects",
  "id": "urn:adsk.objects:os.object:wip.dm.prod/2a6d61f2-49df-4d7b.jpg",
  ...

 

Related Article