I have implemented REST service for upload multiple files into server.But the problem was that i can not get file details if i use FormDataMultiPart
in the REST service.I can get the file content.like wise i tried to get file details like following and it gave me an error saying not supported.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(FormDataMultiPart formParams)
{
Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields();
//Assume i am sending only files with the request
for (List<FormDataBodyPart> fields : fieldsByName.values())
{
for (FormDataBodyPart field : fields)
{
InputStream is = field.getEntityAs(InputStream.class);
String fileName = field.getName();
field.getMediaType();
//Those work perfectly
//This gave me an error
FormDataContentDisposition f=field.getEntityAs(FormDataContentDisposition .class);
System.out.println(f.getFileName());
}
}
}
Please let me know how can i get files details like type,name,size
for each uploaded files if use FormDataMultiPart
.
I was able to access file details finally here is the code snippet.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(FormDataMultiPart formParams)
{
Map<String, List<FormDataBodyPart>> fieldsByName = formParams.getFields();
//Assume i am sending only files with the request
for (List<FormDataBodyPart> fields : fieldsByName.values())
{
for (FormDataBodyPart field : fields)
{
InputStream is = field.getEntityAs(InputStream.class);
String fileName = field.getName();
field.getMediaType();
//This working fine
FormDataContentDisposition f=field.getFormDataContentDisposition();
System.out.println(f.getFileName());
}
}
}
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