File Upload Type

  • 2
  • Question
  • Updated 3 years ago
  • Answered
Is there a way to limit the type of file a user can upload?  I only want PDF files to be allowed...
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb

Posted 4 years ago

  • 2
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Maybe a validation rule on the "Content Type" field of the attachment object? 
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
If memory serves, workflow rules don't support attachments.  You will probably need Apex here.

Here's a nice example to get you started: 

http://blog.prasannadeshpande.com/2013/10/salesforce-trigger-on-attachment/.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
hmmm... this is apex. Since this is the case, can we put together something more meaty using a visualforce page with a skuid:page visualforce component for all things related to attachments. ie. require an description upon uploading.

Shooting from the hip on this one.
Photo of Christopher Johnson

Christopher Johnson

  • 694 Points 500 badge 2x thumb
Curious if anyone got a solution working here...and whether you did it with attachments to the object or the lookup field (to the custom skuid file object).
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
Has anyone come up with a solution for this one?
(Edited)
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Photo of Thimo

Thimo

  • 1,280 Points 1k badge 2x thumb
I have posted something like this before. 

A solution is Javascript. This prevents the user from picking other filetypes than specified. But this is not foolproof since JS could be disabled in the browser.

$('INPUT[type="file"]').change(function (event) {
var ext = this.value.match(/\.(.+)$/)[1]; switch (ext) { case 'pdf': break; default: alert('This Filetype is not supported.'); this.value = ''; window.stop(); } });