0
我已經有了這個代碼工作和運行良好,但現在,幾個修訂後,當我回到其上傳功能,它似乎只讀取請求的元和而不是實際的文件。例如,這就是我試圖上傳txt文件時所得到的結果:澤西上傳接收請求元而不是文件
------ WebKitFormBoundaryF5IARVFzqsY3zpj4Content-Disposition:form-data; NAME = 「文件」 未定義------ WebKitFormBoundaryF5IARVFzqsY3zpj4--
的JS:
$scope.setFiles = function(element) {
$scope.$apply(function($scope) {
console.log('files:', element.files[0]);
// Turn the FileList object into an Array
$scope.files = element.files[0];
$scope.progressVisible = false;
});
};
$scope.analyseFile = function() {
var fd = new FormData();
fd.append("file", $scope.files[0]);
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", "/rest/analysisController/analyseFile");
$scope.progressVisible = false;
xhr.send(fd);
};
和服務器端:
@POST
@Path("analyseFile")
@Produces("application/json; charset=UTF-8")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response analyseFile(
@FormDataParam("file") InputStream uploadedInputStream) throws
RemoteException {
System.out.println(getStringFromInputStream(
uploadedInputStream));
return Response.ok().build();
}
我還包括多依賴:
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.5.1</version>
<scope>provided</scope>
</dependency>