Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm doing a file upload from angular implementing the https://github.com/nervgh/angular-file-upload plugin, my setup it's like this :

var vm = this,
    apiUrl = appConfig.getItem('BASE_API_URL'), // base url;

vm.uploader = $scope.uploader = new FileUploader({
    url: apiUrl + '/invoices/upload',
    headers: {
      "Content-Type": undefined
    }
});

// this function is triggered by a button outside
vm.uploadAll = function () { 
  vm.uploader.uploadAll();
};

on the html I have

    <input id="uploadFileButton"
       type="file"
       nv-file-select
       uploader="FUCtrl.uploader"
       multiple
       style="display: none;"/> 
    // the display none is due to that this input is click triggered
    // by an outside button

the thing is that for start on the client side the post request I see this enter image description here

an image is uploaded (in theory), but the Content-Type is undefined, a missing enctype, and on the other hand on the server side I have this

var express = require('express'),
    multer  = require('multer'),
    cors = require('cors');

var app = express();

app.use(cors());
app.get('*', function(){});

app.use(multer({dest:'./uploads/'}).single('photo'));

app.post('/upload', function(req, res){

  console.log('hit');

  console.log(req.body); // form fields
  console.log(req.files); // form files
  res.status(204).end();

});

app.listen(3000);

but when I recieve the post I see on the console console.log(req.body); // {} console.log(req.files); // undefined

and I can't get any data from the pdf's upload

what am I missing ?

share|improve this question

hey man i don't know about that plugin. but i am using this https://github.com/danialfarid/ng-file-upload plugin and i find very helpful. this is the easiest way to upload a file.

Upload with form submit and validations:

http://jsfiddle.net/danialfarid/maqbzv15/1118/

Upload multiple files one by one on file select:    

http://jsfiddle.net/danialfarid/2vq88rfs/136/

Upload multiple files in one request on file select (html5 only): 

http://jsfiddle.net/danialfarid/huhjo9jm/5/

Upload single file on file select: 

http://jsfiddle.net/danialfarid/0mz6ff9o/135/

Drop and upload with $watch: 

http://jsfiddle.net/danialfarid/s8kc7wg0/400/

Image Crop and Upload 

http://jsfiddle.net/danialfarid/xxo3sk41/590/

share|improve this answer
    
ok, I'll give it a try. thanks for the sugestion – flaalf Jan 4 at 18:19
    
same thing as with nervgh – flaalf Jan 4 at 21:42
1  
transformRequest function will try to serialize our FormData object, so we override it with the identity function to leave the data intact. Angular’s default Content-Type header for POST and PUT requests is application/json, so we want to change this, too. By setting ‘Content-Type’: undefined, the browser sets the Content-Type to multipart/form-data for us and fills in the correct boundary. Manually setting ‘Content-Type’: multipart/form-data will fail to fill in the boundary parameter of the request. jsfiddle.net/bk129/2ff06ud3 it's work for me – bk129 Jan 5 at 18:23
up vote 0 down vote accepted

Finally I've discoverded the solution, on the HTML

nv-file-select

should be

nv-file-select=""

and remove

headers: {
  "Content-Type": undefined
}

from the uploader configuration, apparently those things didn't set the content-type and his boundary well, so I toke them out and goy it to work

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.