limit size of attachments uploaded through file component?

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.skuidify.com/skuid/topics/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>&nbsp; &nbsp; // Get max attachment size from our custom settings<br>&nbsp; &nbsp; XYZ_Settings__c settings = XYZ_Settings__c.getInstance();<br>&nbsp; &nbsp; Integer MaxAttachmentSize = settings.Max_Attachment_Size;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; // Disallow any attachment from Rob or exceeding max size limit<br>&nbsp; &nbsp; for (Attachment a : Trigger.new) {<br>&nbsp; &nbsp; &nbsp; &nbsp; if (UserInfo.getName() == 'Rob Hatch') {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.addError('Skipping attachment since Rob is in the doghouse, again.');<br>&nbsp; &nbsp; &nbsp; &nbsp; } else if (a.BodyLength &gt; MaxAttachmentSize) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.addError('Skipping attachment too large per MAX_ATTACHMENT_SIZE.');<br>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;<br>&nbsp; &nbsp; }<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…