Dropwizard 0.8.1: upload multiple files
I am using dropwizard and I want to upload multiple files at once.
How can I change my code to upload multiple files?
I am using org.glassfish.jersey.media', 'jersey-media-multipart', '2.17'
to upload a file.
Here is my code for uploading one file:
@Path("/uploadPhoto")
@ApiOperation(
value = "Upload a photo for an Ad",
response = Response.class)
@POST
@Timed
@UnitOfWork
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response fileUploaded(@FormDataParam("file") final InputStream inputStream,
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
List<AdImage> images = new ArrayList<AdImage>();
images.add(writeImageAndSave(inputStream
, contentDispositionHeader));
return Response.ok(toJson(images), MediaType.APPLICATION_JSON).build();
}
+3
source to share
1 answer
I found the code here:
@Path("/uploadPhoto")
@ApiOperation(
value = "Upload a photo for an Ad",
response = Response.class)
@POST
@Timed
@UnitOfWork
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response uploadFile(FormDataMultiPart multiPart) {
List<AdImage> images = new ArrayList<AdImage>();
List<FormDataBodyPart> bodyParts =
multiPart.getFields("file");
for (FormDataBodyPart part : bodyParts) {
images.add(writeImageAndSave(part.getValueAs(InputStream.class
), part.getFormDataContentDisposition()));
}
return Response.ok(toJson(images), MediaType.APPLICATION_JSON).build();
}
+3
source to share