allowedFileType allowedMimeType problems #661

Open
opened 2017-03-09 11:49:35 +00:00 by martinpalmieri · 6 comments
martinpalmieri commented 2017-03-09 11:49:35 +00:00 (Migrated from github.com)

Hi,

I have the following issue trying to make the file type validation works.

If I use only allowedMimeType the validator doesn't work for users without office installed.

I can't make the allowedFileType validator work. How is it expecting the file extension?
I make an array like this:
['.png', '.doc']

What am I doing wrong?

Hi, I have the following issue trying to make the file type validation works. If I use only allowedMimeType the validator doesn't work for users without office installed. I can't make the allowedFileType validator work. How is it expecting the file extension? I make an array like this: ['.png', '.doc'] What am I doing wrong?
Bigless27 commented 2017-03-13 14:30:05 +00:00 (Migrated from github.com)

It's because you need to specify the MIME media type ex. ['image/png', 'application/pdf', application/msword'] for .png, .pdf, and .doc respectively.

It's because you need to specify the MIME media type ex. ['image/png', 'application/pdf', application/msword'] for .png, .pdf, and .doc respectively.
martinpalmieri commented 2017-03-13 14:35:28 +00:00 (Migrated from github.com)

@Bigless27 Thanks for your response.

I know that for the allowedMimeType option I need an array like the one you use in your response but what about for the allowedFileType option?

The allowedMimeType option is not working when the user hasn't Office installed (I think for what I read that the Office package install something to make MimeTypes reconocible) and I can't make allowedFileType option work.

@Bigless27 Thanks for your response. I know that for the allowedMimeType option I need an array like the one you use in your response but what about for the allowedFileType option? The allowedMimeType option is not working when the user hasn't Office installed (I think for what I read that the Office package install something to make MimeTypes reconocible) and I can't make allowedFileType option work.
Bigless27 commented 2017-03-13 15:10:47 +00:00 (Migrated from github.com)

@martinpalmieri Sorry read your question incorrectly!

So after looking at the source code I see that it is doing this

FileType.fileTypeDetection = function (inputFilename) { var types = { 'jpg': 'image', 'jpeg': 'image', 'tif': 'image', 'psd': 'image', 'bmp': 'image', 'png': 'image', 'nef': 'image', 'tiff': 'image', 'cr2': 'image', 'dwg': 'image', 'cdr': 'image', 'ai': 'image', 'indd': 'image', 'pin': 'image', 'cdp': 'image', 'skp': 'image', 'stp': 'image', '3dm': 'image', 'mp3': 'audio', 'wav': 'audio', 'wma': 'audio', 'mod': 'audio', 'm4a': 'audio', 'compress': 'compress', 'rar': 'compress', '7z': 'compress', 'lz': 'compress', 'z01': 'compress', 'pdf': 'pdf', 'xls': 'xls', 'xlsx': 'xls', 'ods': 'xls', 'mp4': 'video', 'avi': 'video', 'wmv': 'video', 'mpg': 'video', 'mts': 'video', 'flv': 'video', '3gp': 'video', 'vob': 'video', 'm4v': 'video', 'mpeg': 'video', 'm2ts': 'video', 'mov': 'video', 'doc': 'doc', 'docx': 'doc', 'eps': 'doc', 'txt': 'doc', 'odt': 'doc', 'rtf': 'doc', 'ppt': 'ppt', 'pptx': 'ppt', 'pps': 'ppt', 'ppsx': 'ppt', 'odp': 'ppt' };

What I think is happening is that allowedFileType can't tell exactly what extension is being uploaded only the general type like image/audio/ect. So what you want to do is allowedFileType: ['image', 'doc'] to allow a png file and a doc file.

@martinpalmieri Sorry read your question incorrectly! So after looking at the source code I see that it is doing this ` FileType.fileTypeDetection = function (inputFilename) { var types = { 'jpg': 'image', 'jpeg': 'image', 'tif': 'image', 'psd': 'image', 'bmp': 'image', 'png': 'image', 'nef': 'image', 'tiff': 'image', 'cr2': 'image', 'dwg': 'image', 'cdr': 'image', 'ai': 'image', 'indd': 'image', 'pin': 'image', 'cdp': 'image', 'skp': 'image', 'stp': 'image', '3dm': 'image', 'mp3': 'audio', 'wav': 'audio', 'wma': 'audio', 'mod': 'audio', 'm4a': 'audio', 'compress': 'compress', 'rar': 'compress', '7z': 'compress', 'lz': 'compress', 'z01': 'compress', 'pdf': 'pdf', 'xls': 'xls', 'xlsx': 'xls', 'ods': 'xls', 'mp4': 'video', 'avi': 'video', 'wmv': 'video', 'mpg': 'video', 'mts': 'video', 'flv': 'video', '3gp': 'video', 'vob': 'video', 'm4v': 'video', 'mpeg': 'video', 'm2ts': 'video', 'mov': 'video', 'doc': 'doc', 'docx': 'doc', 'eps': 'doc', 'txt': 'doc', 'odt': 'doc', 'rtf': 'doc', 'ppt': 'ppt', 'pptx': 'ppt', 'pps': 'ppt', 'ppsx': 'ppt', 'odp': 'ppt' };` What I think is happening is that allowedFileType can't tell exactly what extension is being uploaded only the general type like image/audio/ect. So what you want to do is allowedFileType: ['image', 'doc'] to allow a png file and a doc file.
martinpalmieri commented 2017-03-13 15:13:48 +00:00 (Migrated from github.com)

@Bigless27 Thanks again!

I will try with what you're telling me. Sounds good!

I'll let you know how it comes out

@Bigless27 Thanks again! I will try with what you're telling me. Sounds good! I'll let you know how it comes out
eversummer commented 2017-03-27 10:03:52 +00:00 (Migrated from github.com)

I tried 'image' and it worked. But when I tried 'compress' and uploaded a file ending with '7z', it didn't work.

I tried 'image' and it worked. But when I tried 'compress' and uploaded a file ending with '7z', it didn't work.
ozknemoy commented 2020-04-06 10:11:24 +00:00 (Migrated from github.com)

i simply added this filter in my config

new FileUploader({
  filters: [{name: 'customFileType', fn:(file: FileLikeObject) => {
    const ext = file.name.split('.').pop();
    return allowedFileType.indexOf(ext) > -1
  }}]
});
i simply added this filter in my config ``` new FileUploader({ filters: [{name: 'customFileType', fn:(file: FileLikeObject) => { const ext = file.name.split('.').pop(); return allowedFileType.indexOf(ext) > -1 }}] }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#661