I'm implementing a file upload in a web application.
The front-end is written in angularJS and uses the angular-file-upload package (the one that can be found at this link https://github.com/nervgh/angular-file-upload).
The back-end is Java / Jersey Web Services.
The uploaded file contains a WebKitFormBoundary header and footer, like this:
------WebKitFormBoundarylqskdjlqksdjl
Content-Disposition: form-data; name="upload"; filename="foo.bar"
Content-Type: multipart/form-data
Therefore, I'm not sure whether I'm uploading a file or a request. And of course, my back-end application considers that the uploaded files are corrupted and would not display them unless those lines are removed (for now manually).
Bottom line is : how do I get rid of that header and footer in the uploaded file?
Here are some code samples.
Once again: angularJS angular-file-upload
item.headers = {
'Content-Disposition': 'attachment; filename="' + item.file.name + '"',
'Content-Type': 'multipart/form-data'
};
and Java / Jersey
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("someurl/{fileName}")
public Artifact uploadArtifact(InputStream uploadedStream, @PathParam("fileName") String fileName) throws Exception;
I'm wondering if the Content-Disposition: attachment
in my angularJS part could be what's messing it up?
And that it should rather be Content-Disposition: form-data
?
Thx in advance!
You need to place @FormDataParam
annotation in order to properly handle boundary.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("someurl/{fileName}")
public Artifact uploadArtifact(
@FormDataParam("file") InputStream uploadedStream,
@FormDataParam("file") FormDataContentDisposition fileDetails,
@PathParam("fileName") String fileName) throws Exception;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With