5

I am trying to implement some limitation to the file types allowed for upload using dropzone.js. Somehow the below code works for Word, Excel and Powerpoint documents but it doesn't work for .zip and .rar. Any suggestions?

   Dropzone.options.filedrop = {
        maxFilesize: 4096,
        acceptedMimeTypes: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/excel,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/x-rar-compressed, application/x-rar, application/octet-stream,application/zip, compressed/rar,application/rar,application/x-compressed,multipart/x-zip,multipart/x-rar',
        }
Subliminal Hash
  • 13,614
  • 20
  • 73
  • 104
  • What do you mean 'does not work'? Do you have an example of the error that occurs, or better yet, something to look at? – NT3RP Jun 12 '13 at 21:13
  • Which browsers have you tested this with? Does it consistantly not work for .rar files across browsers or only in some (that support dropzone.js ofcourse). – Christian P. Jun 19 '13 at 13:17
  • tested on latest chrome and firefox. Do not need IE. Yes I tried various rar files with no luck with all sorts of mime types I could find. – Subliminal Hash Jun 19 '13 at 13:52
  • I can see this behavior as well. I use `acceptedFiles: 'application/zip'`, and although it show only zip files in the file selection window, Dropzone doesn't send them. If I don't specify zip mime type, it does send zip files. – seldary Aug 31 '13 at 15:42
  • Possible duplicate of [File input 'accept' attribute - is it useful?](http://stackoverflow.com/questions/181214/file-input-accept-attribute-is-it-useful) – Mogsdad Jan 08 '16 at 03:12

2 Answers2

3

If this question (and its answers) are any indication, you may be able to avoid explicitly listing the mime-type in favour of simple .extension style.

From what I have examined in the dropzone.js source code, all that the library does it check that the mimetypes are valid, and then assign them as the accept attribute on the file input element.

Community
  • 1
  • 1
NT3RP
  • 15,262
  • 9
  • 61
  • 97
  • When I say "don't work" basically I mean: With the acceptedMimeTypes defined in my code (as can be seen from my question) works in a way that I can upload excel, word, powerpoint and even zip files. However, although the mime type for .rar is defined, it does not accept .rar files. Similarly any other format is not accepted (so the code works). But for .rar files although the mime types are defined, still the upload fails.. – Subliminal Hash Jun 19 '13 at 12:18
  • You are right. I'll implement the extension check as soon as possible. https://github.com/enyo/dropzone/issues/182 – enyo Jun 24 '13 at 12:50
0

By default dropzone supports all mime types. if your requirement is not much specific just remove acceptedMimeTypes option. doing this will let you upload all kind of file extensions.

Anand Shah
  • 611
  • 7
  • 14