我有一个带有2个文件和一个文本区域的表单,用于发布到使用node.js创建的服务器端 处理节点/快递上的上传部分(4.0)我使用了multer。 在角度方面处理上传时,我在angular-file-upload
上转发我试图保持快递部分现在非常简单,只是为了测试它实际上是否正常工作
/// NODE JS EXPRESS
app.use(multer({ dest: __dirname + '/public/uploads/',
rename: function (fieldname, filename) {
return filename; //.replace(/\W+/g, '-').toLowerCase() + Date.now()
}
}))
/// ANGULAR
cmsApp.controller("MyController", ['$scope', '$location', '$upload', function($scope, $location, $upload) {
$scope.title = $location;
//$scope.saveMiscs = function() {
$scope.submit = function() {
console.log("saving miscs");
var file_1 = $scope.formfile1;
var file_2 = $scope.formfile2;
//console.log('file is ', JSON.stringify(file_regole), " + " + JSON.stringify(file_statuto));
$scope.upload = $upload.upload({
url: '/api/misc/filupload1', //upload.php script, node.js route, or servlet url
file: file_1, // or list of files ($files) for html5 only
}).progress(function(evt) {
console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
}).success(function(data, status, headers, config) {
// file is uploaded successfully
console.log("upload completed: ", data);
});
};
$scope.onFileSelect = function($files) {
$scope.files = angular.copy($files);
console.log($scope.files); // Returns my object
}
$scope.setFiles = function(element) {
$scope.$apply(function($scope) {
console.log(element.files);
if(element.id == "form__file1")
file_1 = element.files;
else if(element.id == "form__file2")
file_2 = element.files;
});
};
}]);
/// ANGULAR HTML
<form id="modify_form" ng-submit="submit()" ng-controller="MyController" enctype="multipart/form-data">
<div class="intro_detail" style="margin-top:36px;">
<div class="dotted blue"></div>
<div class="box_title">Documents</div>
Load file 1 here<br>
<input type="file" id="form_1_fld" class="" name=""
onchange="angular.element(this).scope().setFiles(this);" ng-model="file_1"/><br>
<br>
Load file 2 here<br>
<input type="file" id="form_2_fld" class="" name=""
onchange="angular.element(this).scope().setFiles(this);" ng-model="file_1"/>
<div class="dotted spacer_small blue"></div>
</div><!-- END INTRO DETAIL -->
<div class="form_viewport">
<div class="full_container">
<label>Write something in here:</label><br>
<textarea ng-model="text_desc" id="form__desc"></textarea>
</div>
<div class="clearfix"></div>
<div class="full_container" style="text-align:center; margin-top:50px;">
<input type="button" class="submit_cancel" value="Cancel" />
<input type="submit" class="submit_save" value="Save" />
</div>
</div><!-- END FORM VIEWPORT -->
</form>
如果我尝试使用普通形式发布,这不涉及角度,一个简单的多部分形式,其中包含一个&#34;文件&#34; field,nodejs / multer获取文件和上传没有问题,但是如果 我在游戏中使用涉及express的这种情况,看起来没有文件发布到服务器。