feature request: restrict types of files that are uploaded #41
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?
Can you add functionality to restrict the types of files that are uploaded? For example, allow gifs & jpegs only, etc?
Yes you can.
From this file
22307d266f/components/file-upload/file-uploader.class.tsyou can see that there is possibility to addallowedFileTypeorallowedMimeTypeoptions toFileUploader.Example:
That would allow only png images to be uploaded.
Hi @mentholi
Really nice. But do you know how to show an error if it's a wrong file type ? Thanks.
I think if The Module exported FileLikeObject you could override onWhenAddingFileFailed.
Hi @markmaynard
Can you please put an example how to do that? Thanks.
@sampath-lokuge unfortunately it won't work until this project exports FileLikeObject. I'll try and show an example of how it would work when I get back in the office Monday.
OK sure.No problem @markmaynard 👍
So the following public function exists, which looks like a callback hook to me. The only problem is that FileLikeObject is not exported in the module so there is now way to access it. If it is the intention of the project to make onWhenAddingFileFailed a callback, and the export is added to the project you could do the following.
`
uploader.onWhenAddingFileFailed = (item:FileLikeObject, filter:any, options:any) => {
//do your operations here
return {item, filter, options};
}
`
Maybe you could contribute the change of adding the export and see what the maintainers think?
Fixed in this PR: https://github.com/valor-software/ng2-file-upload/pull/619