1
anglejs를 사용하여 파일을 업로드하고 json 객체를 nodejs 서버로 단일 요청으로 보냅니다. 그럼 난 불을 지르고에서이 CONSOLE.LOG를 얻을 :FormData에 파일 추가가 anglejs에서 작동하지 않습니다.
-----------------------------8791641017658 Content-Disposition: form-data; name="model" {"phone":"asasasa","description":"121212112","payment":"2121212121","shipping":"121221221","imageurl":"21212112","price":"212112212","status":"new"} -----------------------------8791641017658--
그래서, 이름 = "파일은"여기에 표시되지 않습니다.
그리고 // print out "{}"
이 도와주세요 nodejs 서버에서 CONSOLE.LOG (req.files), 감사합니다!
$scope.uploadFile = function(files) {
uploadsService.uploadFile(files).then(function(promise){
$scope.code = promise.code();
$scope.fileName = promise.fileName();
});
};
그리고보기에 :
$scope.files = [];
$scope.$on("fileSelected", function (event, args) {
$scope.$apply(function() {
//add the file object to the scope's files collection
$scope.files.push(args.file);
console.log($scope.files);
});
});
$scope.create = function() {
$scope.seller_submit = {
phone: this.phone,
description: this.description,
payment: this.payment,
shipping: this.shipping,
imageurl: this.imageurl,
price: this.price,
status: this.status
};
$http({
method: 'POST',
url: '/articles/'+ $routeParams.articleId,
headers: { 'Content-Type': undefined },
transformRequest: function (data) {
var formData = new FormData();
formData.append("model", angular.toJson(data.model));
for (var i = 0; i < data.files; i++) {
formData.append("file" + i, data.files[i]);
}
return formData;
},
data: { model: $scope.seller_submit, files: $scope.files }
}).
success(function (data, status, headers, config) {
alert("success!");
}).
error(function (data, status, headers, config) {
alert("failed!");
});
매력처럼 작동합니다. – JayPea
하나의 파일 만 업로드 할 수 있습니까? – nam