Selecting multiple files and uploading them using Jersey

故事扮演 提交于 2019-12-03 21:35:56

It works OK for me to use the 'FormDataMultiPart'.

Here is the Java code, the FormDataContentDisposition object(formParams) contains actual file content.

List<FormDataBodyPart> parts = formParams.getFields("file");
for (FormDataBodyPart part : parts) {
    FormDataContentDisposition file = part.getFormDataContentDisposition();
}

In the JS side, I use the FormData object and push several files with the same name:

for (var i = 0; i < files.length; i++)
    fd.append('file', files[i]);

Wish it will help

This thing worked for me pretty well:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadMultiple(@FormDataParam("file") FormDataBodyPart body){
    for(BodyPart part : body.getParent().getBodyParts()){
        InputStream is = part.getEntityAs(InputStream.class);
        ContentDisposition meta = part.getContentDisposition();
        doUpload(is, meta);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!