angular-file-upload icon indicating copy to clipboard operation
angular-file-upload copied to clipboard

Cant get Complete Resopnse : Headers is not a function

Open sumh opened this issue 9 years ago • 2 comments

Hi , I encounter a problem when I use Anjular(nginx port 80) upload files to node.js(same server port 3000,already set the Access-Control-Allow-Origin *)

the file is success upload to the server , but cant get complete response

*Cant get Complete Resopnse : Headers is not a function *

other Node API working normally, only this upload API has this problem

Anjular config: _app.controller('FileUploadCtrl', ['$scope', 'FileUploader', function($scope, FileUploader) { var uploader = $scope.uploader = new FileUploader({ url:'http://127.0.0.1:3000/upload/new', withCredentials:true,

});

_

Nodejs config: _ form.parse(req, function(err, fields, files) {

    var inputFile = files.file[0];
    var uploadedPath = inputFile.path;
    var dstFileName = inputFile.originalFilename;
    var dstPath = './public/upload/' + dstFileName

    fs.rename(uploadedPath, dstPath, function(err) {
      if(err){
            res.json({"success":false);
       res.end()
      } else {
        res.json({"success":true,"filename":dstFileName});

      }
    });

  })

_ Web Console Error Code angular.js:8477 Uncaught TypeError: headers is not a functiondefaultHttpResponseTransform @ angular.js:8477(anonymous function) @ angular-file-upload.min.js:5forEach @ angular.js:339g._transformResponse @ angular-file-upload.min.js:5c.onload @ angular-file-upload.min.js:5

node response header:(2 response )

1st OPTION

HTTP/1.1 200 OK

X-Powered-By 3.2.1 Access-Control-Allow-Origin http://127.0.0.1 Access-Control-Allow-Credentials true Access-Control-Allow-Headers Content-Type, Content-Length, Authorization, Accept, X-Requested-With Access-Control-Allow-Methods PUT,POST,GET,DELETE,OPTIONS Content-Type application/json; charset=utf-8 Allow POST Content-Length 4 ETag W/"4-oCQ57CKdi+DnSwwWAjkjEA" Set-Cookie avos:sess=; path=/; expires=Thu, 14 Apr 2016 18:19:29 GMT; httponly Set-Cookie avos:sess.sig=xxxx; path=/; expires=Thu, 14 Apr 2016 18:19:29 GMT; httponly Date Thu, 14 Apr 2016 17:19:29 GMT Connection keep-alive

2nd HTTP/1.1 200 OK X-Powered-By 3.2.1 Access-Control-Allow-Origin http://127.0.0.1 Access-Control-Allow-Credentials true Access-Control-Allow-Headers Content-Type, Content-Length, Authorization, Accept, X-Requested-With Access-Control-Allow-Methods PUT,POST,GET,DELETE,OPTIONS Content-Type application/json;charset=utf-8 Set-Cookie avos:sess=xxxxx path=/; expires=Thu, 14 Apr 2016 18:19:29 GMT; httponly Set-Cookie avos:sess.sig=xxxx; path=/; expires=Thu, 14 Apr 2016 18:19:29 GMT; httponly Date Thu, 14 Apr 2016 17:19:29 GMT Connection keep-alive Content-Length 0

Seems headers function cant read this response header

function defaultHttpResponseTransform(data, headers) {

if (isString(data)) {

// strip json vulnerability protection prefix
data = data.replace(JSON_PROTECTION_PREFIX, '');
var contentType = headers('Content-Type');
if ((contentType && contentType.indexOf(APPLICATION_JSON) === 0) ||
    (JSON_START.test(data) && JSON_END.test(data))) {
  data = fromJson(data);
}

} return data; }

sumh avatar Apr 14 '16 17:04 sumh

Got the same. And I have no clue on how to resolve this.

chintalpatel89 avatar Aug 01 '17 07:08 chintalpatel89

I don't know your AngularJS version. I can suppose that backward compatibility between ng's versions was broken.

nervgh avatar Aug 03 '17 06:08 nervgh