Dropwizard 0.8.1:多文件上传(Dropwizard 0.8.1 : multiple file upload)

编程入门 行业动态 更新时间:2024-10-27 12:30:43
Dropwizard 0.8.1:多文件上传(Dropwizard 0.8.1 : multiple file upload)

我正在使用dropwizard,我想一次上传多个文件。

如何更改我的代码以上传多个文件?

我正在使用org.glassfish.jersey.media', 'jersey-media-multipart', '2.17'进行文件上传。

这是我的单个文件上传代码:

@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(); }

I'm using dropwizard and I want to upload multiple files at once.

How could I change my code to upload multiple files?

I'm using org.glassfish.jersey.media', 'jersey-media-multipart', '2.17' for file upload.

Here is my code for a single file upload :

@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(); }

最满意答案

我发现这里是代码:

@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(); }

I found it here is the code :

@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(); }

更多推荐

本文发布于:2023-07-09 14:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1087007.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件上传   Dropwizard   upload   file   multiple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!