On Friday, 16 January, 2015 05:51 PM, Thierry Boileau wrote:
> Hello,
> I guess you are refering to this page of the user guide:
> http://restlet.com/technical-resources/restlet-framework/guide/2.3/extensions/fileupload
>
> The code is exactly the same for the GAE edition, except that you cannot
> write File directly as is it forbidden by the GAE platform.
>
> You can still have access to the FileItem#getInputStream() method.
>
>
> Best regards,
> Thierry Boileau
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3094350
>
Theierry,
I am not sure but it seems the sample you gave throws error and we
cannot use the repackaged apache package with Restlet.
So I improvised, I manage to upload large files with Restlet and GAE
with this code:
@Override
public void upload(Representation entity) throws Exception {
if (entity != null) {
if
(MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), true)) {
Request restletRequest = getRequest();
HttpServletRequest servletRequest =
ServletUtils.getRequest(restletRequest);
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator fileIterator =
upload.getItemIterator(servletRequest);
while (fileIterator.hasNext()) {
FileItemStream item = fileIterator.next();
String name = item.getName();
byte[] content =
ByteStreams.toByteArray(item.openStream());
// do stuff with content
}
} else {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
}
} else {
setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
}
}
Perhaps you can share this with Restlet documentation so community would
benefit to this code. Or perhaps you can see some issues with the code.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3094355