Is there a way to limit what types of files can be uploaded? #750
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Are there some options you can pass to limit to just pdfs and image/jpg?
You could add an
acceptattribute to your inputs.e.g.
accept=".pdf, image/jpg"https://html.spec.whatwg.org/multipage/forms.html#attr-input-accept
You can add the files types when the uploader is constructed.
public uploader: FileUploader = new FileUploader( { url: URL, allowedMimeType: ['application/pdf', 'image/jpeg'] });@RyanDrx maybe a dumb question but is there a way to say "only images" or "not images"?
I tried to use by allowing mime type like below
public uploader: FileUploader = new FileUploader( { url: URL, allowedMimeType: ['application/pdf', 'image/jpeg'] });
but it is not working, did anyone tried this ?
the below callback 'onWhenAddingFileFailed ' will be called if your file format not matching.
this.uploader = new FileUploader({
allowedMimeType: ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template']
});
Add the allowedMimeType or allowedFileType It will be work.
Working Stackblitz Code example: https://stackblitz.com/edit/ng2-file-upload-example