Upload Files to the Forma Files Tool
This tutorial demonstrates how to upload files to Forma Files tool. The steps include finding the ID of the folder where you want to upload the files, creating an empty storage object for the file, generating a signed S3 URL, uploading the file to the signed URL, creating the first version of the file, and, optionally, creating additional versions of the file.
If you want to upload a file to Forma Sheets, see the Upload Sheets tutorial.
In order to complete the upload process, you need to manually review and publish the file in Forma Files. For more details, see the Help documentation.
For more details about Forma Data 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, project, and folder.
Step 1: Find the Hub ID for the Forma Hub
The first few steps of the tutorial demonstrate how to create an empty storage object in the folder where you want to upload the file. This involves iterating through several Data Management endpoints to find the folder ID.
Call GET hubs to find the hub ID for the Forma hub that contains the folder you want to upload the file to.
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 folder you want to upload the file to is in a hub 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 upload the file to.
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 upload the file to.
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); in this example, the Project Files folder, and note the folder ID (data.id) - urn:adsk.wipprod:fs.folder:co.BJU3PTc4Sd2CmXM492XUiA
Step 4: Find the Nested Folder ID
If you want to upload the document to 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 document to. For the first iteration, use the top-level folder ID. (urn:adsk.wipprod:fs.folder:co.BJU3PTc4Sd2CmXM492XUiA).
Request
Response
In this example, assume that My First Files is the folder that contains the file you want to upload.
Find the folder (data.attributes.name), and note the folder ID (data.id) - urn:adsk.wipprod:fs.folder:co.QneBBX7evT2JSrpeQXga0.
Step 5: Create a Storage Object
Use the project ID (b.cGVyc29uYWw6d2l) and the folder ID (urn:adsk.wipprod:fs.folder:co.QneBBX7evT2JSrpeQXga0) to call POST projects/:project_id/storage to create an empty storage object for the file in the folder.
Note that you need to assign a filename and file extension (PNG or JPG) to the name parameter (My First File.jpg).
Request
Repsonse
Note the object ID (data.id) - urn:adsk.objects:os.object:wip.dm.prod/2a6d61f2-49df-4d7b.jpg.
The object ID includes the following sections: <urn:adsk.objects:os.object>:<bucket key>/<object key>
Note the bucket key - wip.dm.prod and the object key - 2a6d61f2-49df-4d7b.jpg
Step 6: Generate a Signed S3 URL
Use the bucket key (wip.dm.prod) and the object key (2a6d61f2-49df-4d7b.jpg) to call GET buckets/:bucketKey/objects/:objectKey/signeds3upload to generate a signed URL for the storage object.
This endpoint supports generating multiple signed URLs, which allows you to upload multiple chunks of the same file in parallel. For more information, see GET signeds3upload.
Request
Repsonse
Note the uploadKey and the urls response attributes.
Step 7: Upload a File to the Signed URL
To upload the file to the signed URL, use a PUT method and the urls attribute as the URI.
Note that you should not use a bearer token with this call.
Request
Note that a successful call (200) returns an empty response.
Step 8: Complete the Upload
Use the bucket key (wip.dm.prod) the object key (2a6d61f2-49df-4d7b.jpg`) and the upload key (AQICAHifrJ6-BSHUmjAat4..........QWI-fuvghN23akgePMdmykV) to call POST buckets/:bucket_key/objects/:object_key/signeds3upload to complete the upload.
This endpoint needs to be called within 24 hours from the time you began uploading the file.
Request
Repsonse
The file has been uploaded to the storage object.
Step 9: Create the First Version of the File
Use the project ID (b.cGVyc29uYWw6d2l), the folder ID (urn:adsk.wipprod:fs.folder:co.BJU3PTc4Sd2CmXM492XUiA), and the Object ID (urn:adsk.objects:os.object:wip.dm.prod/2a6d61f2-49df-4d7b.jpg) to call POST projects/:project_id/items to create the first version of the uploaded file.
Request
Response
Note the item ID (data.id) - urn:adsk.wipprod:dm.lineage:AeYgDtcTSuqYoyMweWFhhQ, and version ID (inlcuded[id]) - urn:adsk.wipprod:fs.file:vf.AeYgDtcTSuqYoyMweWFhhQ?version=1.
Step 10: Create Additional Versions of the File
To create an additional version of the file, you need to create a new storage object (step 5), upload the new version to the object (step 6), and use the item ID you retrieved in step 7 to call POST projects/:project_id/versions.
Request
Response
Congratulations! You have uploaded a file to Forma Files tool.
Imported from the Autodesk Platform Services documentation: https://aps.autodesk.com/en/docs/acc/v1/tutorials/files%20/upload-document-s3.