How to restrict the File Upload only to images?

  • 1
  • Question
  • Updated 2 years ago
  • Answered
I want users to be able to upload images via the File Upload Component. But nothing prevents them from uploading any file.

Does anyone know how to restrict that?
Photo of Thimo

Thimo

  • 1,280 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Prior conversations have suggested that this sort of validation would probably best be done in APEX...

https://community.skuidify.com/skuid/topics/file-upload-type
Photo of Thimo

Thimo

  • 1,280 Points 1k badge 2x thumb
Temporary fixed it with javascript.

For anyone interested:

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

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Sweet!  Good work Thimo...
Photo of Vasu Deva

Vasu Deva

  • 100 Points 100 badge 2x thumb
Hi Thimo, I have similar requirement. How can we call this snippet from file upload button?