Miscellaneous

Creating and Uploading Assets

Create assets from a public URL

When using the createAsset mutation, setting the sourceUrl property to a publicly accessible URL will automatically download the file for you. You'll need to set the filename property to the name you want and to set the uploadStatus property to "PENDING". The upload process will set the correct pathproperty for you.

Uploading assets

Uploading files, such as from a form submission, happens in two parts:

First, you’ll send TakeShape a GraphQL query using the uploadAssets mutation. The mutation takes a list of TSFile objects, which have two properties: a name, which is a filename like cats.jpg; and a type, which is a MIMEtype like image/jpeg. It returns a list of created asset records with an accompanying uploadUrl, which you’ll need for the next part.

After you’ve created the asset records and gotten their upload URLs, you’ll need to send a PUT request to the uploadUrl with the file in the request’s body. If the request is successful, you’ll get an empty 200 response back and your assets will be available in your TakeShape project’s Asset Library.

Example code

This example Node.js script demonstrates the process of submitting a single file to your TakeShape Asset Library: