我正在 JAX RS 中进行文件传输 - 使用 jersey multipart。
问题是我不太明白为什么响应会改变网站,我只是希望像普通 XHR 请求这样的表单留在网站上,然后我想要一种通过回调获得通知的方法。但是我找不到任何方法来做到这一点?
HTML:
<form action="resources/picture/upload" method="post" enctype="multipart/form-data">
<p>
Select a Category : <select id="cat" name="cat"> <option value="1234">Icons</option></select>
</p>
<p>
Select an image : <input type="file" name="file"/>
</p>
<input type="hidden" id="appId" name="appId" value="1"/>
<input type="submit" value="Upload It" onclick=" NewPicture()" />
</form>
JAX RS:
@POST
@Path("/upload/{pictureId}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response overrideExistingFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail,
@PathParam("pictureId") Long pictureId) {
Picture oldPicture = repository.get(Picture.class, pictureId);
String uploadedFileLocation = oldPicture.getUrl();
File file = writeToFile(uploadedInputStream, uploadedFileLocation, true);
if (file != null) {
System.out.println("File attempted saved @ " + file.getAbsolutePath());
}
return Response.status(200).build();
}