Yes you can.
From this file https://github.com/valor-software/ng2-file-upload/blob/22307d266fe1a25e109e9315515ca05156e38591/components/file-upload/file-uploader.class.ts you can see that there is possibility to add `allowedFileType` or `allowedMimeType` options to `FileUploader`.
Example:
``` typescript
let uploader = new FileUploader({ url: "http://myapiurl.com", allowedMimeType:["image/png"] });
```
That would allow only png images to be uploaded.
I think if The Module exported FileLikeObject you could override onWhenAddingFileFailed.
I think if [The Module](https://github.com/valor-software/ng2-file-upload/blob/development/src/file-upload/file-upload.module.ts) exported FileLikeObject you could override onWhenAddingFileFailed.
@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.
@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.
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?
So the following public [function](https://github.com/valor-software/ng2-file-upload/blob/development/src/file-upload/file-uploader.class.ts#L216) exists, which _looks_ like a callback hook to me. The only problem is that [FileLikeObject](https://github.com/valor-software/ng2-file-upload/blob/development/src/file-upload/file-like-object.class.ts#L5) is not exported in the [module](https://github.com/valor-software/ng2-file-upload/blob/development/src/file-upload/file-upload.module.ts#L10) 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?
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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 https://github.com/valor-software/ng2-file-upload/blob/22307d266fe1a25e109e9315515ca05156e38591/components/file-upload/file-uploader.class.ts you can see that there is possibility to add
allowedFileTypeorallowedMimeTypeoptions 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