Looking for a specific example showing how to use the REST API to upload Version media to AWS S3

Looking for a specific example showing how to use the REST API to upload Version media to AWS S3

The API documentation’s “Uploading a File” section (ShotGrid REST API v1) has a crytpic entry “This is type of upload requires not extra step before making the complete upload request” (not entirely sure what that means exactly).

Haven’t found any AWS S3 - specific examples. Have tried a variety of methods and iterations, but keep getting errors and/or non-responses. Tried scouring AWS documentation as well, so far to no avail.

Thanks in advance.

1 Like

Bump ^
I’m running into the same question, as I’ve been unable to get this workflow to work.

@Codiegladney
Ultimately I figured it out for my particular pipeline (took a lot of research and a certain amount of wild guessing). Happy to pay it forward if it helps you.
Let me know if this does the trick: use --data-binary instead of -d
If that doesn’t help, post or DM your upload code, and I’ll take a look.

2 Likes

@trillion Hmm, I’m not seeing a DM feature on these forums, but I do see the option on Autodesk’s forums.

I found the DM feature but it didn’t work. Sure, try the AutoDesk forum. Maybe that’ll work.

1 Like

@Codiegladney
I wasn’t able to log into AutoDesk forum. Are you comfortable w/ posting the upload code in this post?

Since you quoted from the non-multipart documentation, I assume you are using this (only works for files below 500mb). The flow is:

  • request upload url
  • upload to url with PUT request, and content type headers set
  • call complete url, which is returned from the first request (See “Completing an upload” section)

What the documentation means is that no extra steps are required for the non-multipart upload, in contrast to the multipart upload.
On the right hand side of this documentation, there are example requests and responses.

If you are getting errors, you should share them here to understand the situation better.

@mmoshev side note, fwiw, I regularly upload files >1gb using the non-multipart REST API option. Now that you mention a 500mb limit I remember it in the documentation, but for whatever reason, it hasn’t been a problem so far. Maybe AWS S3 has evolved?

@trillion
Okay, so I am doing the following:

  1. GET request upload url: {{host}}/api/v1/entity/projects/{{projectId}}/image/_upload/?filename=cg
  • This returns a 200, with an S3 URL in the “upload” field that is used in step 2, as well as a “data” field that is used in step 3
  1. PUT request to the S3 URL that was in the “upload” field from step 1.
  • Body of this request is a binary cg.png
  • Response is 200 OK
  1. POST to {{host}}/api/v1/entity/projects/{{projectId}}/image/_upload?filename=cg
  • In the body I am leaving “upload_data” empty object, and the “upload_info” value is the “data” object from step 1.
  • I am getting a 400 response, with this error: “Thumbnail could not be uploaded: Validation failed: The file must be an image”

I’ve tried doing this to update a pre-existing version as well, and I run into the same error. Maybe my step 2 is being done incorrectly?

@Codiegladney

Try this schematic…

Create a new Version

curl -X POST \
 {YourShotGridDomain}/api/v1/entity/versions/ \
 -H  Authorization: Bearer {YourToken} \
 -H 'Accept: application/json' \
 -H 'Content-Type: application/json' \
 -d {YourPostDataAsJsonData}

Update existing Version

curl -X PUT \
{YourShotGridDomain}/api/v1/entity/versions/{idOfYourTargetVersion} \
 -H 'Authorization: Bearer ${YourToken} \
 -H 'Accept: application/json' \
 -H 'Content-Type: application/json' \
 -d {YourPostDataAsJsonData}

Request upload URL

curl -X GET  \
 {YourShotGridDomain}/api/v1/entity/versions/{idOfYourTargetVersion}/sg_uploaded_movie/_upload?filename={YourFileName} \
 -H 'Authorization: Bearer ${YourToken} \
 -H 'Accept: application/json'

Execute upload

curl -v -X PUT {UrlReceivedFromPrior} \
 --data-binary @{Path/To/Your/File} \
 -H 'Content-Type: {MimeTypeOfYourFile}' \
 -H 'Content-Size: {FileSizeInBitesOfYourFile}'
1 Like

“The file must be an image”. Perhaps filename=cg was an illustration, but is it really an image?
If it was the real parameter you passed, I think it should be filename=cg.png, containing the extension.

1 Like

@trillion this worked! Thank you so much for taking the time to help me get unstuck.

1 Like

@Codiegladney I know the feeling. Glad that worked!!