Download Files from Forma Files Tool
This tutorial demonstrates how to download files from Forma Files tool. The steps include finding the ID of the folder that contains the file, locating the storage object for the file, generating a signed S3 URL, and downloading the file from the signed S3 URL.
For more details about Forma files management, see the Data Management API.
Before You Begin
- Register an app, and select the Data Management and Forma APIs.
- Acquire a 3-legged OAuth token with
data:createdata:readanddata:writescopes. - Verify that you have access to the relevant Forma hub and Forma project.
- Note the name of the Forma hub, project, and folder that contains the file you want to download.
Step 1: Find the Hub ID for the Forma Hub
The first few steps of the tutorial demonstrate how to find the ID of the folder that contains the file you want to download, which invovles iterating through several Data Management endpoints.
Call GET hubs to find the hub ID for the Forma hub that contains the file you want to download.
Note that the Forma hub ID corresponds to a Data Management hub ID. To convert an account ID into a hub ID you need to add a “b.” prefix. For example, an account ID of c8b0c73d-3ae9 translates to a hub ID of **b.**c8b0c73d-3ae9.
Request
Response
In this example, assume that the hub (and the corresponding Data Management hub) that contains the file you want to download is called My First Hub.
Find the hub (data.name), and note the hub ID - b.cGVyc29uYWw6cGUyOWNjZjMy.
Step 2: Find the Project ID
Use the hub ID (b.cGVyc29uYWw6cGUyOWNjZjMy) to call GET hubs/:hub_id/projects to get a list of all the projects in the hub. Find the project ID of the project that contains the folder you want to download the file from.
Note that the project ID in Forma corresponds to the project ID in the Data Management API. To convert a project ID in Forma to a project ID in the Data Management API, you need to add a “b.” prefix. For example, a project ID of a4be0c34a-4ab7 translates to a project ID of **b.**a4be0c34a-4ab7.
Request
Response
In this example, assume that My First Project is the project that contains the folder you want to download the document from.
Find the project (data.attributes.name), and note the project ID (data.id) - b.cGVyc29uYWw6d2l.
Step 3: Find the Folder ID
Use the hub ID (b.cGVyc29uYWw6cGUyOWNjZjMy) and the project ID (b.cGVyc29uYWw6d2l) to call GET hubs/:hub_id/projects/:project_id/topFolders to get the top-level folders.
Request
Response
Find the relevant folder (data.attributes.name), and note the folder ID (data.id) - urn:adsk.wipprod:fs.folder:co.BJU3PTc4Sd2CmXM492XUiA
If you want to download a file from a folder nested under the top-level folder, you need to call GET projects/:project_id/folders/:folder_id/contents repeatedly through the hierarchy of folders until you find the Folder ID of the folder you want to upload the file to. For the first iteration, use the top-level folder ID (urn:adsk.wipprod:fs.folder:co.BJU3PTc4Sd2CmXM492XUiA).
Step 4: Find the Storage Object ID for the File
Use the project ID (b.cGVyc29uYWw6d2l) and the Projet Files folder ID (urn:adsk.wipprod:fs.folder:co.BJU3PTc4Sd2CmXM492XUiA) to call GET projects/:project_id/folders/:folder_id/contents to get the storage object ID.
Request
Response
}
In this example, assume that My First File is the file that you want to download.
Find the file (included.attributes.name), and note the storage object ID (relationships.storage.data.id) - urn:adsk.objects:os.object:wip.dm.prod/72d5e7e4-89a7-4cb9-9da0-2e2bbc61ca8e.dwg.
The storage object ID includes of the following sections: <urn:adsk.objects:os.object>:<bucket_key>/<object_key>
Note the bucket key - wip.dm.prod and the storage object key - 72d5e7e4-89a7-4cb9-9da0-2e2bbc61ca8e.dwg
Step 5: Generate a Signed S3 URL
Use the bucket key (wip.dm.prod) and the object key (72d5e7e4-89a7-4cb9-9da0-2e2bbc61ca8e.dwg) to call GET buckets/:bucketKey/objects/:objectKey/signeds3download to generate a signed URL for the storage object, which you can use to download the file directly from S3.
Request
Response
Step 6: Download the File
To download the file from the signed URL, use a GET method and the url attribute as the URI.
Note that you should not use a bearer token with this call.
Request
Congratulations! You have downloaded a file from the Forma Files tool.
Imported from the Autodesk Platform Services documentation: https://aps.autodesk.com/en/docs/acc/v1/tutorials/files%20/download-document-s3.