Skip to content

Commit

Permalink
Made the maxFilesize message configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
enyo committed May 10, 2013
1 parent f22ad36 commit 13fee3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/dropzone.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class Dropzone extends Em
# If null, no text will be added at all.
dictFallbackText: "Please use the fallback form below to upload your files like in the olden days."

# If the filesize is too big.
dictFileTooBig: "File is too big ({{filesize}}MB). Max filesize: {{maxFilesize}}MB."

# If the file doesn't match the file type.
dictInvalidFileType: "You can't upload files of this type."

Expand Down Expand Up @@ -507,7 +510,7 @@ class Dropzone extends Em
# `acceptedMimeTypes` check.
accept: (file, done) ->
if file.size > @options.maxFilesize * 1024 * 1024
done "File is too big (" + (Math.round(file.size / 1024 / 10.24) / 100) + "MB). Max filesize: " + @options.maxFilesize + "MB"
done @options.dictFileTooBig.replace("{{filesize}}", Math.round(file.size / 1024 / 10.24) / 100).replace("{{maxFilesize}}", @options.maxFilesize)
else unless Dropzone.isValidMimeType file.type, @options.acceptedMimeTypes
done @options.dictInvalidFileType
else
Expand Down
13 changes: 11 additions & 2 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,24 @@ describe "Dropzone", ->
dropzone = null
beforeEach ->
element = Dropzone.createElement """<div></div>"""
dropzone = new Dropzone element, url: "url", acceptedMimeTypes: "audio/*,image/png"
dropzone = new Dropzone element, maxFilesize: 4, url: "url", acceptedMimeTypes: "audio/*,image/png"

describe ".accept()", ->

it "should properly accept files which mime types are listed by acceptedMimeTypes", ->
it "should pass if the filesize is OK", ->
dropzone.accept { size: 2 * 1024 * 1024, type: "audio/mp3" }, (err) -> expect(err).to.be.undefined

it "shouldn't pass if the filesize is too big", ->
dropzone.accept { size: 10 * 1024 * 1024, type: "audio/mp3" }, (err) -> err.should.eql "File is too big (10MB). Max filesize: 4MB."

it "should properly accept files which mime types are listed in acceptedMimeTypes", ->

dropzone.accept { type: "audio/mp3" }, (err) -> expect(err).to.be.undefined
dropzone.accept { type: "image/png" }, (err) -> expect(err).to.be.undefined
dropzone.accept { type: "audio/wav" }, (err) -> expect(err).to.be.undefined

it "should properly reject files when the mime type isn't listed in acceptedMimeTypes", ->

dropzone.accept { type: "image/jpeg" }, (err) -> err.should.eql "You can't upload files of this type."


Expand Down

0 comments on commit 13fee3d

Please sign in to comment.