이제는 파일 업로드에 각도 파일 업로드 패키지를 사용하고 있습니다. item.upload()를 누르면 파일이 성공적으로 업로드되었다고 주장하지만 req.body가 비어있는 것을 볼 수 있습니다. 도와주세요! 여기 AngularJS에서 ExpressJs로 파일을 업로드하지 못했습니다.
그것을 처리하기 위해 각 코드 :var uploader = $scope.uploader = $fileUploader.create({
scope: $scope, // to automatically update the html. Default: $rootScope
url: '/api/teams/upload',
formData: [
{ key: 'value' }
],
filters: [
function (item) { // first user filter
$scope.previewImage(item);
return true;
}
]
});
을 그리고 여기에 업로드 트리거 할 수있는 방법입니다
uploader.bind('afteraddingfile', function (event, item) {
// console.info(item.file);
console.info('After adding a file', item);
// console.log('item.upload();');
item.upload();
});
을 그리고 마지막으로 여기에 명시 JS 코드 :
exports.upload = function(req, res) {
// console.log('req.headers');
// console.log(req.headers);
console.log('req.body');
console.log(req.body);
무엇이 잘못 되었나요? 당신은 단지에 필요한 익스프레스의 이전 버전에서
var bodyParser = require('dy-parser');
//...
var app = express();
//...
app.use(bodyParser()); // pull information from html in POST
var busboy = require('connect-busboy');
app.use(busboy());
:
이익스프레스 사에서 당신이 당신의 서버에서 body parser
을 설정해야 enctype="multipart/form-data"
로 ....