How to do multipart/mixed upload with Restlet? #1387
cyberquarks
started this conversation in
General
Replies: 1 comment
-
I made a test for this: @Post
public void acceptFormUpload(Representation entity) throws Exception {
if (entity == null) {
throw new ResourceException(400); // Bad request
}
if (MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
FileItemFactory factory = new DiskFileItemFactory();
RestletFileUpload fileUpload = new RestletFileUpload(factory);
List<FileItem> fileItems = fileUpload.parseRepresentation(entity);
if (fileItems == null) {
throw new ResourceException(400); // Bad request
}
for (FileItem fileItem : fileItems) {
if (fileItem.isFormField()) {
String fieldName = fileItem.getFieldName();
String fieldValue = fileItem.getString();
System.out.println("Field name: " + fieldName + ", Value: " + fieldValue);
}
else {
String fieldName = fileItem.getFieldName();
String fileName = fileItem.getName();
long fileSize = fileItem.getSize();
System.out.println("File size: " + fileSize + " bytes");
}
}
} else {
throw new ResourceException(415); // Unsupported media type
}
} I tried this with:
And with:
And:
It works. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Which version of Restlet supports multipart/mixed upload?
The idea is to be able to upload a binary along with JSON in one request.
Beta Was this translation helpful? Give feedback.
All reactions