![](/img/trans.png)
[英]Couldn't upload file using multer in node js + angular js application
[英]Couldn't catch the response through Angular file upload
我正在尝试使用POST方法和REST调用将单个文件上传到服务器。 使用下面的代码,我可以上传模块,但是在上传之后,它显示了一些错误。 有人可以帮我解决这个问题吗?
我的HTML代码:
<form name="myForm" enctype="multipart/form-data" >
<input type="file" ngf-select ng-model="picFile" name="file" file="file"
accept="" ngf-max-size="2MB" required
ngf-model-invalid="errorFile">
<button ng-disabled="!myForm.$valid"
ng-click="uploadPic(picFile)">Submit</button>
</form>
我的JS代码:
var app = angular.module('fileUpload', ['ngFileUpload']);
app.controller('MyCtrl', ['$scope', 'Upload','fileUpload', function ($scope, Upload,fileUpload) {
$scope.uploadPic = function(file) {
fileUpload.uploadFileToUrl(file);
}
}]);
app.service('fileUpload', ['$http','Upload', function ($http,Upload) {
this.uploadFileToUrl = function(file){
file.upload = Upload.upload({
url: 'http://localhost:8080/openmrs/ws/rest/v1/module/?',
headers: {'Content-Type': 'multipart/form-data;boundary=gc0p4Jq0M2Yt08jU534c0p'},
transformRequest: angular.identity,
data: {file: file}
});
file.upload.then(function (response) {
}, function (response) {
if (response.status > 0)
}, function (evt) {
});
}
}]);
错误信息 :
org.springframework.http.converter.HttpMessageNotWritableException:无法编写JSON:类加载器为空模块:openhmis.inventory(通过参考链:org.openmrs.module.Module [“ moduleActivator”]); 嵌套的异常是org.codehaus.jackson.map.JsonMappingException:类加载器为null模块:
错误消息显示为“无法编写JSON”。 这意味着它无法将JSON类型响应写入请求。 请检查您的响应类型并确认是否为JSON类型。
有很多响应类型,它们是
最好使用如下所示的“接受”状态来更改标题,
headers: {'Content-Type': undefined , 'Accept': 'application/xhtml+xml;charset=UTF-8'}
这是工作 ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.