Angularjs 将php文件上载端点转换为node.js/express
抱歉,我以前没有在node.js中使用文件上载 目前,我使用angular服务,该服务使用Angularjs 将php文件上载端点转换为node.js/express,angularjs,node.js,express,Angularjs,Node.js,Express,抱歉,我以前没有在node.js中使用文件上载 目前,我使用angular服务,该服务使用FormData,并向php提交$http post请求,然后在那里通过move\u uploaded\u file()上传,工作正常 js代码 myApp.service('fileUpload', ['$http', function ($http) { this.uploadFileToUrl = function(file, uploadUrl){ var fd = new
FormData
,并向php提交$http post请求,然后在那里通过move\u uploaded\u file()
上传,工作正常
js代码
myApp.service('fileUpload', ['$http', function ($http) {
this.uploadFileToUrl = function(file, uploadUrl){
var fd = new FormData();
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
})
.error(function(){
});
}
}]);
myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
$scope.uploadFile = function(){
var file = $scope.myFile;
console.log('file is ' + JSON.stringify(file));
var uploadUrl = "upload.php";
fileUpload.uploadFileToUrl(file, uploadUrl);
};
}]);
html
可能是@jakerella的副本,该解决方案不起作用
<input type="file" file-model="myFile"/>
<button ng-click="uploadFile()">upload me</button>
routes.post("/upload",function(req,res,next){
console.log(req.Files);
console.log(req.body);
});