feature request: restrict types of files that are uploaded #41

Open
opened 2016-02-01 21:29:26 +00:00 by HLaiveling · 8 comments
HLaiveling commented 2016-02-01 21:29:26 +00:00 (Migrated from github.com)

Can you add functionality to restrict the types of files that are uploaded? For example, allow gifs & jpegs only, etc?

Can you add functionality to restrict the types of files that are uploaded? For example, allow gifs & jpegs only, etc?
mentholi commented 2016-08-30 09:38:04 +00:00 (Migrated from github.com)

Yes you can.

From this file 22307d266f/components/file-upload/file-uploader.class.ts you can see that there is possibility to add allowedFileType or allowedMimeType options to FileUploader.

Example:

let uploader = new FileUploader({ url: "http://myapiurl.com", allowedMimeType:["image/png"] });

That would allow only png images to be uploaded.

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.
Sampath-Lokuge commented 2017-01-21 14:33:26 +00:00 (Migrated from github.com)

Hi @mentholi

Really nice. But do you know how to show an error if it's a wrong file type ? Thanks.

Hi @mentholi Really nice. But do you know how to show an error if it's a wrong file type ? Thanks.
markmaynard commented 2017-01-27 19:50:48 +00:00 (Migrated from github.com)

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 commented 2017-01-27 22:59:26 +00:00 (Migrated from github.com)

Hi @markmaynard

Can you please put an example how to do that? Thanks.

Hi @markmaynard Can you please put an example how to do that? Thanks.
markmaynard commented 2017-01-27 23:01:42 +00:00 (Migrated from github.com)

@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.
Sampath-Lokuge commented 2017-01-27 23:05:31 +00:00 (Migrated from github.com)

OK sure.No problem @markmaynard 👍

OK sure.No problem @markmaynard :+1:
markmaynard commented 2017-01-28 19:10:39 +00:00 (Migrated from github.com)

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?
markmaynard commented 2017-02-07 13:08:28 +00:00 (Migrated from github.com)
Fixed in this PR: https://github.com/valor-software/ng2-file-upload/pull/619
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#41