I have a Suitelet where the user can input multipl...
# ask-stanley-ai
s
I have a Suitelet where the user can input multiple files. How can I only allow files to be inputted under 5 MB?
c
AI generated answer (using internal Slack threads):
In order to restrict the file size to under 5MB in a Suitelet, you can add a validation in the Suitelet script itself. Unfortunately, there is no built-in way to restrict the file size directly in the Suitelet form field. Here is a sample code snippet that shows how you can validate the file size:
Copy code
javascript
var fileObj = request.files['custpage_file'];
if(fileObj.size > 5000000) { // file size is in bytes
    throw 'File size cannot exceed 5MB';
}
In this code,
request.files['custpage_file']
is used to get the file object from the request. The
size
property of the file object gives the size of the file in bytes. If the size exceeds 5MB (5000000 bytes), an error is thrown. Please note that this validation happens after the file is uploaded, so it won't prevent the user from selecting a file larger than 5MB. However, it will prevent the Suitelet from processing a file that is larger than 5MB. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824707031
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.819580138
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815429688
Please provide your feedback on this answer.