We’ve got 4 custom lookup fields on a detail object, which each relate to a specific image of the vehicle being stored (interior image, exterior image etc). We want to prevent users from uploading files larger than e.g. 500kb, (for faster page loads when previewing images, and these images will be transferred onto a document)
Would it be possible to limit the size of attachments uploaded through the file component?
You could write a Before Insert on Attachment trigger and restrict the body size. Don’t know if Skuid provides access to the file properties in the JS API.
Greg, here are some answers from our Dev Team:
We don’t provide an out of the box way to limit the file size. Normally, you’d want this sort of validation to be handled server side, because anything you rig up client side in JavaScript could be manipulated before submit to get around your validation. Of course, if this is all for an internal app where you can say, “Come on, folks. Play nice” this may not be an issue.
A trigger on Attachment like Irvin suggested could work, but you’ll need to get pretty selective with how it’s enforced, lest you block other Attachments larger than 500 KB that you do want to allow.You could also take a look at this conversation. https://community.skuid.com/t/how-to-upload-images-photos-efficently
It doesn’t solve all your questions, but does offer some cues.
trigger AttachmentFilter on Attachment bulk (before insert) {<br> // Get max attachment size from our custom settings<br> XYZ_Settings__c settings = XYZ_Settings__c.getInstance();<br> Integer MaxAttachmentSize = settings.Max_Attachment_Size;<br> <br> // Disallow any attachment from Rob or exceeding max size limit<br> for (Attachment a : Trigger.new) {<br> if (UserInfo.getName() == 'Rob Hatch') {<br> a.addError('Skipping attachment since Rob is in the doghouse, again.');<br> } else if (a.BodyLength > MaxAttachmentSize) {<br> a.addError('Skipping attachment too large per MAX_ATTACHMENT_SIZE.');<br> } <br> }<br>}
Ummm, seriously? Again?
Irvin that’s brilliant. Definitely the simplest most immediate solution. The only question is do I leave the reference to Rob in there for my future dev team to ponder over - ‘who’s this Rob guy?’
Long term it would be great to allow users to crop/adjust images themselves during the upload as per your post Rob - the images our users put in will be merged into drawloop documents so making it easy for them to maintain consistent dimensions and image sizes would be a huge bonus.
Sorry, could not resist… was in meetings all day and I needed a little levity to break up the monotony.
No worries at all…
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.