Unable to set allowedMimeType to application/csv or text/csv #728

Open
opened 2017-04-03 11:00:07 +00:00 by bikram-eNest-tech · 2 comments
bikram-eNest-tech commented 2017-04-03 11:00:07 +00:00 (Migrated from github.com)

When I want to restrict to upload only the CSV file the current code doesn't let me to do so. It always fire onWhenAddingFileFailed in case of "application/csv". Any help appreciated

When I want to restrict to upload only the CSV file the current code doesn't let me to do so. It always fire onWhenAddingFileFailed in case of "application/csv". Any help appreciated
saidavdic commented 2017-04-07 07:31:15 +00:00 (Migrated from github.com)

Hi,
As I can see, there is no support for text/csv mime type.
But you can create your own file type filter:

this.uploader = new FileUploader({
url: URL,
filters: [{
name: 'extension',
fn: (item: any): boolean => {
const fileExtension = item.name.slice(item.name.lastIndexOf('.') + 1).toLowerCase();
return fileExtension === 'csv' ;
}
}]
});

Hi, As I can see, there is no support for text/csv mime type. But you can create your own file type filter: this.uploader = new FileUploader({ url: URL, filters: [{ name: 'extension', fn: (item: any): boolean => { const fileExtension = item.name.slice(item.name.lastIndexOf('.') + 1).toLowerCase(); return fileExtension === 'csv' ; } }] });
sreedharbukya commented 2017-11-14 12:26:17 +00:00 (Migrated from github.com)

I have used allowedMimeTypes as follows, It worked for me.

 this.uploader = new FileUploader({
        url: "",
        queueLimit: 1,
        isHTML5: true,
        maxFileSize: 1048576, // 1 MB Limit
        allowedMimeType: ['text/csv'] // CSV File limitation
      });

this.uploader.onWhenAddingFileFailed = function (item: FileLikeObject, filter: any, options: any) {
      console.log(item);
      console.log(filter);
      console.log(options);
      // todo: show alert that you tried uploading wrong files
    };


I have used allowedMimeTypes as follows, It worked for me. ``` this.uploader = new FileUploader({ url: "", queueLimit: 1, isHTML5: true, maxFileSize: 1048576, // 1 MB Limit allowedMimeType: ['text/csv'] // CSV File limitation }); this.uploader.onWhenAddingFileFailed = function (item: FileLikeObject, filter: any, options: any) { console.log(item); console.log(filter); console.log(options); // todo: show alert that you tried uploading wrong files }; ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#728