Upload Filesize Limit

Options
oburrell
oburrell Member
edited December 2022 in ❓Other questions

I searched but couldn't find how to limit the file size for uploads in XANO.

Is this possible somehow?

If not, I think this would be a really good feature to save bandwidth.

Tagged:

Best Answers

  • Xano Support Chat
    Xano Support Chat Administrator

    ADMIN

    Answer ✓
    Options

    Hey @oburrell the metadata of when you create the file gives you the size of the file in bytes. You can set a precondition to enforce that the file the user is uploading is less than a byte size that you specify.

    Here is a similar video where you can enforce a user's total uploads are under a certain size but you can apply similar logic with the precondition on an individual upload basis.


  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Answer ✓
    Options

    This is a great method! Getting the file resource data allows you to check the size before creating the file at all. Order of operations matters which is why you didn't find success with the Precondition in position 1. Nice solution :)

Answers

  • oburrell
    oburrell Member
    Options

    I am trying to limit the file size for each uploaded file to say 3MB and created the endpoint like this:

    This works but I am not quite sure if there is a better way. First I tried to have the Precondition first in the function stack and no "Get File Resource Data" but at that point the size is not known. It seems that the file gets downloaded twice this way (first at the "Get File Resource Data" and again with the "Create Attachment From File").