Cant get Complete Resopnse : Headers is not a function
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; }
Got the same. And I have no clue on how to resolve this.
I don't know your AngularJS version. I can suppose that backward compatibility between ng's versions was broken.