diff --git a/index.js b/index.js index f539d34..d180bf7 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,11 @@ app.use(require("multer")( { dest: __dirname + '/public/uploads', rename: function(fieldname, filename) { - return filename; + // Append a random number to the file name to avoid overwriting + // files with the same name. This is especially important since some + // devices (such as the iPad) name all images image.jpeg, even when + // multiple images are uploaded with one HTTP request. + return filename + "-" + Math.floor(Math.random()*1000000000); } })); app.use(require("body-parser").json()); diff --git a/views/upload.jade b/views/upload.jade index b3ae5f5..0242d8b 100644 --- a/views/upload.jade +++ b/views/upload.jade @@ -5,14 +5,13 @@ block content p Select files or paste text into the textbox (or both). Then click the upload button. - form(action="/upload" method="post" enctype="multipart/form-data") + form(action="/upload", method="post", enctype="multipart/form-data") h2 Text upload textarea(rows="10", name="text") h2 File upload - p Warning: If you upload two files with the same name, the second will overwrite the first! - input(type="file" name="files" multiple) + input(type="file", name="files", multiple) h2 Upload it