Http 400, errors for Direct upload

Error:

{‘errors’: [{‘status’: ‘400’, ‘title’: ‘Validation Error’, ‘detail’: ‘“value” must be of type
object’}]}

Python:

def upload_asset(self, path):   #png file
    headers = {
    "x-api-key": myapikey}
    with open(path, 'rb') as f:
        data = f.read()
        res = requests.request(
            "POST",
            'https://api.shotstack.io/ingest/stage/upload',
            headers=headers, data=data

Ive tried many more modifications(headers, request), but I keep getting error messages. Kindly suggest.

It looks like you are sending the file data body to the endpoint which will give you this error.

Uploading files is a two step process. The first step is to request a signed URL, the signed URL is where you upload (PUT) the file to.

So in your code above you will need to remove the data payload and only POST to the endpoint with the headers.

You should then receive a response with a URL that looks similar to:

https://shotstack-ingest-api-v1-sources.s3.ap-southeast-2.amazonaws.com/5ca6hu7s9k/zzyafe82-4tvb-ku1r-87ty-0io5sv0mtrdl/source?AWSAccessKeyId=ASIAWJV3NVDML6LI2ZVG&Expires=1672819007&Signature=9M76gBA%2FghV8ZYvGTp3alo5Ya%2Fk%3D&x-amz-acl=public-read&x-amz-security-token=IQoJb3JpZ2luX2VjEJ%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDmFwLXNvdXRoZWFzdC0yIkcwRQIhAJHrqMCRk7ACXuXmJICTkADbx11e2wUP0RZ3KRdN3%2BGwAiAYt%2FIHlM8rcplCgvsvqH%2BBtSrlCW%2BUeZstwuwgq45Y3iqbAwjo%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAMaDDQz...M0yerN4Zot%2FREHgCSzajNII9Xio%2F0%3D

Then use that URL in a new request using PUT, the returned signed URL and the payload. You should not send any headers or the x-api-key as you are using the signed URL which has credentials built in to it.

I am not sure exactly how you would do this with Python but the cURL request is like this:

curl -X PUT -T image.png https://shotstack-ingest-api-v1-sources.s3.ap-southeast-2.amazonaws.com/5ca6hu7s9k/zzyafe82-4tvb-ku1r-87ty-0io5sv0mtrdl/source?AWSAccessKeyId=ASIAWJV3NVDML6LI2ZVG&Expires=1672819007&Signature=9M76gBA%2FghV8ZYvGTp3alo5Ya%2Fk%3D&x-amz-acl=public-read&x-amz-security-token=IQoJb3JpZ2luX2VjEJ%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDmFwLXNvdXRoZWFzdC0yIkcwRQIhAJHrqMCRk7ACXuXmJICTkADbx11e2wUP0RZ3KRdN3%2BGwAiAYt%2FIHlM8rcplCgvsvqH%2BBtSrlCW%2BUeZstwuwgq45Y3iqbAwjo%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F8BEAMaDDQzMzExNTIxMT...OMOpVA%2FAg9RM0yerN4Zot%2FREHgCSzajNII9Xio%2F0%3D

Here is the full documentation to upload directly and the two step process: Ingest Files with the Ingest API | Shotstack Documentation.

Right I did see it, thats what confused me, because API examples use a POST.

Thanks for your fast input.

Will try and make this clearer in the docs so it is easier to follow.

1 Like