Uploading files to S3

Options

I'm trying to upload the files stored on Xano to S3.

When I test the AWS api through Postman I attach the binary file and it works.

In Xano I tried putting the path and the url of the file as the parameter.  It does create a file in my bucket as well, however it’s missing the content (the file object) itself and it’s just a few bytes in size.

Any suggestions on how to solve this?

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    edited July 2023
    Options

    @pacifist9722 — speaking blindly here without seeing the API documentation for what you're using, but I see a couple potential issues:

    First, you're setting the path as your file. Your params is literally:

    {
     "@/vault/HttQ……………………": ""
    }
    
    

    You probably want to send the entire file as the params section if they didn't specific a parameter name.

    Secondly, you're passing your file as text. You likely will want to pass this through the File Resource input or the Create File Resource form variable. See more about passing files through external APIs in our documentation: https://docs.xano.com/working-with-data/functions/external-api-request#multipart-support

    I'm guessing the last example under Multipart support is similar to what you need but please reference the API documentation from AWS

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    S3 Uploads use a PUT that simply ship the bytes as the payload. If you a file resource, use the "get data from file resource" function under content uploads and call that, say, bytes. Then make bytes the "params" in your PUT request. Don't use the object-plus-set technique. It's just straightforwardly going into params to put the bytes into the body of the request. Then set the Content-Type header to the content-type of the file in question. (if its unknown, use Content-Type: octet/stream).

    Assuming you have a correctly signed upload URL, you should be on your way!

    Working with AWS is tricky! It's definitely part of the hardest 5% of no-code challenges we solve together in State Change office hours and our loom-enabled forum.