bleenco / ngx-uploader

Angular File Uploader
https://ngx-uploader.jankuri.me
MIT License
757 stars 349 forks source link

Enhancement: allowedContentTypes to match HTML5 input "accept" #499

Open zbagley opened 5 years ago

zbagley commented 5 years ago

Description

Currently allowedContentTypes for input options only seems to accept very specific MIME types. The expected results would be that the allowedContentTypes array would match how a DOM <input accept="<allowedContentTypes>" performs.

Specific Issues

Noticed mismatch on: blanket MIME types (image/*, audio/*) specific extensions (.dae, .dxf)

Reproduction

Using the demo .ts and .html files, append options to include:

allowedContentTypes: ['image/*', '.dae']

This results in the input rejecting all image files and .dae extension files.

Append <input accept="image/*, .dae" /> and image files and .dae extensions are no longer rejected, but are the only files allowed to be selected for upload.

andzejsw commented 4 years ago

Any progress?

andzejsw commented 4 years ago

Some Mime types not recognized, like for example .asc should be text/plain but instead it shows empty string. Then easier is to write method in addedToQueue upload case and then check file extensions, before pushing in upload files list:

            case 'addedToQueue':
                let extension = this.file.name.split('.')[1];
                if (this.allowedFileExtensions.indexOf(extension) === -1) {
                    this.notification.danger('notifications.only-cypher-files');
                    return;
                }
                this.files.push(output.file);
                break;