Maximum Filesize Restriction

Is there a way we can set a maximum filesize at the point a user selects a file to upload?

We have a seperate system where we have used Create to build a front end form. The data is pulled by this other system via API calls and it recently ran into an issue with an uploaded file which was too big for it to handle. A user had uploaded a saved outlook email file which had many large unrelated attachments.

We have been asked if we are able to restrict the filesize to prevent this from happening, however I don’t seem to be able to find a built in way to do this.

Hi Oliver,

Based on your response I’m not clear on whether your query is in regards to preventing the file size when uploading a file to Liberty Create, or within the API itself. However, I will provide options for both and you can assess the best option for your build.

I hope this guide provides something useful for your use case :slight_smile:

----- Limiting the file upload in the Liberty Create -----

By default, Liberty Create only allows file uploads up to 100mb (although some apps will have 512mb maximum file size upload, depending on the platform version and architecture). There is no way to increase/decrease/configure this limit out-the-box.

There are a few things you can do here, but both will require Code Studio.

  1. Dropzone File Uploader
    From the Community AppShare, there is a ‘Dropzone File Uploader’ widget you can download, which allows you to drag-and-drop multiple files to the widget to upload them. One of the settings offered within this widget it the ability to specify the maximum file size that can be uploaded. Depending on your configuration, this might be a good way of preventing large file sizes easily.

  2. Code Studio widget/presenter
    The next option is similar to the first, but you could create a Code Studio widget or presenter where you can specify a file size limit. This would give you more flexibility to configure everything yourself, but you would need to know how to utilise and build within Code Studio.

----- Limiting the file sent in the API -----

There are a few things that you can do to manage your API function from sending data over a certain size limit - Based on your message i’m assuming the file is being sourced from your Liberty Create app, so my advise will be from this point of view. This is also based on your configuration, so you will need to assess how you could use the suggestions within your configuration.

  1. Base64 encoding
    If you want to include large files rather than reduce the maximum file size limit, you could consider using a processor offered out-the-box, base64 encoding, which could allow up to an extra 33% larger files to be transferred.

  2. File size subset (file attribute from file object)
    If the file is stored in a file-type object, you can use the file size attribute offered within the file-type object and create a subset based on this (within your subset, you will need to specify the maximum file size in bytes). You can then apply this subset wherever appropriate.

  3. Code Studio (file attribute from file object)
    As this is within an API, you could probably create a field/data processor to validate the file size, when using the file attribute. From there you can do anything you want - The world is your oyster at that point!
    You could trigger errors/warning using the cs.error() or cs.warning() functions. You could fail that record within the API. You can omit if from the payload (etc)

  4. Image/File property
    Unfortunately, if you’re using a file/image property as opposed to the object (which contains the attributes) then it’s can become quite difficult to extract the file size without creating logic in Code Studio. If you want to explore this option, then you would probably need to use the cs.record_field_file_url() function to get the file location, and then make a cs.curl() request to get the file/images property’s size that way.