angularjs - Multiple file upload not working -



angularjs - Multiple file upload not working -

i'm trying upload multiple files along form info using angular package, https://github.com/danialfarid/angular-file-upload. here's code:

var files = ... // files (this working, don't worry) homecoming $upload.upload({ url: '/some_resource', type: 'post', headers: { 'content-type': 'multipart/form-data' }, data: { myobj: json.stringify(myobj) }, file: files });

if there single file in files, uploads correctly — if there's multiple files, nil uploaded. in docs, says:

upload multiple files: html5 formdata browsers (not ie8-9) if pass array of files file alternative upload of them in 1 request.

i'm not quite sure if i'm doing wrong or not (i'm using chrome).

my next guess issue on backend (i'm using express.js). since request 'multipart/form-data', i'm running through multer (https://github.com/expressjs/multer), so:

app.post('/some_resource', multer({ dest: '../tmpuploads' }), function(req, res) { console.log(req.files); // <- prints {} when uploading multiple files });

like said, setup works when files contains single file. help appreciated!

here's how got working.

var files = [...] // array of file objects var filenames = [...] // name in [filenames] shares same index file names in [files] homecoming $upload.upload({ url: '/some_resource', type: 'post', headers: { 'content-type': 'multipart/form-data' }, data: { myobj: json.stringify(myobj) }, file: files, fileformdataname: filenames });

my node.js backend:

app.post('/some_resource', multer({ dest: '../tmpuploads' }), function(req, res) { // req.files object, where, in terms of frontend // , backend variables, req.files[filenames[i]] = files[i] });

angularjs file-upload express

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Php operator `break` doesn't stop while -