I’m doing a filetransfer in JAX RS – With jersey multipart.
The problem is I don’t quite get why the response makes the site change, I simple want the form like a normaly XHR request to stay on the site and then I’d like a way to get notified with a callback. But I can’t find any way to do this?
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();
}
i have solution of one of your problem that is redirection after uploading a file
if you dont want to redirect after uploading file than remove return statement from method
overrideExistingFileand write void as a return type of that method.like
and still you want to get a notified than open a upload box in iframe and get notified using frame.parent without any redirection.