Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple file upload feature or documentation #10

Closed
dantheman213 opened this issue Oct 12, 2016 · 11 comments
Closed

multiple file upload feature or documentation #10

dantheman213 opened this issue Oct 12, 2016 · 11 comments

Comments

@dantheman213
Copy link

This module doesn't appear to allow multiple file upload. Or if it does the documentation does not cover it.

@richardgirges
Copy link
Owner

Hi there,

The module does allow multiple file uploads - I'll update the documentation to cover this.

If you were two upload two files (i.e. sampleFile1 and sampleFile2), they would both be accessible from:

req.files.sampleFile1

and

req.files.sampleFile2

@ghost
Copy link

ghost commented Nov 29, 2016

var thisFile;
if (!req.files) {
res.send('No files were uploaded.');
return;
}
for (var key in req.files) {
thisFile = req.files[key];
console.log(req.files[key].name);
thisFile.mv('public/images/' + req.files[key].name, function(err) {
if (err) {
console.log(err);
}
else {
console.log('File uploaded!');
}
});

}

I tried this and it works. Having 1 or more input type as file. But each input file had a different name and posted as enctype="multipart/form-data" works.
But a documentation would be very much appreciated because it is really hard to get this clue since I need to read issues to see if some had a similar problem to get a clue.

@dantheman213
Copy link
Author

thanks for the information and for also adding a task to write in documentation that covers multiple file upload.

@richardgirges
Copy link
Owner

Release v0.0.6 is up. Better documentation as well. Hope things are going well with this package!

@ghost
Copy link

ghost commented Jan 14, 2017

Just read through the current documentation and it is very clear on how to work with this module . It goes straight to the point to describe the very use case senarios which is awesome .
Good practical explanation

@bpiv400
Copy link

bpiv400 commented Nov 26, 2017

Hi, express-fileupload clearly supports multiple file upload when the files are coming from inputs with different names. But does the package support uploading multiple files from a single input tag with the multiple attribute? Something like this:
<input type="file" name="myPictures" multiple></input>

@yagoml
Copy link

yagoml commented May 13, 2018

The same of @bpiv400. Need get multiple files for the same input

@shyamvir2506
Copy link

shyamvir2506 commented Feb 6, 2019

Hi @bpiv400 ,
this package is supporting uploading multiple files from a single input tag with the multiple attribute. Something like this:
<input type="file" name="filename" multiple></input>

You can upload files like below.

app.post('/', function(req, res){
if(req.files){
var file = req.files.filename;
for(var i = 0 ; i < file.length; i++){
file[i].mv('./upload/'+file[i].name, function(err){
if(err){
res.send(err);
}
})

    }
    res.send('all files uploaded.');
}

})

@mathewk2017
Copy link

Hi, @shyamvir2506 it is not working for me.can you log that file variable so that I can check where I went wrong

@shadab14meb346
Copy link

shadab14meb346 commented Sep 26, 2019

I tried and it is working for multiple files upload using for loop like req.files.uploadedfile.lenth is giving the number of the uploaded files, but when I am uploading only a single file then req.files.uploadedfile.lenth is coming as undefined and with this my for loop logic to upload file is not working in case of single upload. If someone can help in this.

@RomanBurunkov
Copy link
Collaborator

Hi @shadab14meb346 ,

If you upload single file, middleware adds an object, not an array so there is no 'length' parameter.
You need to check whether you got an array or just a single object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants