第一次带着重复感。我试图将文件上传到休息状态,我参考了本教程:http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-resteasy/ 但是我收到了错误。 MultiPartFormDataInput似乎不被接受,因为它是一个接口。我错过了什么吗? 感谢。
这是我的终点:
packer-provisioner-shell.exe 3940 TCP 127.0.0.1 10000 0.0.0.0 0 LISTENING
packer-builder-virtualbox-iso.exe 11284 TCP 127.0.0.1 10000 127.0.0.1 49568 ESTABLISHED
packer.exe 12180 TCP 127.0.0.1 49568 127.0.0.1 10000 ESTABLISHED
packer.exe 12180 TCP 127.0.0.1 49571 127.0.0.1 10000 SYN_SENT
这是我的表格:
@CrossOrigin(origins = "http://localhost:8000")
@RequestMapping(value="upload", method = RequestMethod.POST, consumes = "multipart/form-data")
public Response uploadFile(MultipartFormDataInput input) {
String fileName = "";
Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
List<InputPart> inputParts = uploadForm.get("file");
for (InputPart inputPart : inputParts) {
try {
MultivaluedMap<String, String> header = inputPart.getHeaders();
fileName = getFileName(header);
//convert the uploaded file to inputstream
InputStream inputStream = inputPart.getBody(InputStream.class,null);
byte [] bytes = IOUtils.toByteArray(inputStream);
//constructs upload file path
fileName = UPLOADED_FILE_PATH + fileName;
writeFile(bytes,fileName);
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
return Response.status(200)
.entity("UPLOAD is called, Uploaded file name : " + fileName).build();
}