Thanks Thierry,

I am pretty sure I saw that doc item, but, as I mentioned, the use of 
"DiskFactoryItem" kinda scared me. Thanks for the reassurance. I can rewrite 
using FormDataSet if you or Jerome think that's better.

        bjorn

On Oct 8, 2012, at 3:51 AM, Thierry Boileau wrote:

> Hello Bjorn,
> 
> from what I see, you are following the right way (see 
> http://www.restlet.org/documentation/2.1/jse/ext/org/restlet/ext/fileupload/RestletFileUpload.html#getItemIterator%28org.restlet.representation.Representation%29)
> 
> Best regards,
> Thierry Boileau
> ps : there could be another way using the FormDataSet class taken from the 
> org.restlet.ext.html extension. But there's something I miss about the aim of 
> this class. I check with Jérôme.
> 
> Hey all,
> 
> I'm trying to create an endpoint on my server where users can post one or 
> more large files. These files will then be processes and pushed to S3. For 
> testing purposes, I am not processing and pushing to S3 yet, just calculating 
> an sha1 hash and printing it to std out. The code below works, but I couldn't 
> figure out how to do this without accessing classes called "FileItemStream" 
> and, more ominously, "DiskFileItemFactory", so I wanted to make sure this 
> code doesn't actually try to write the files to disk. I want the input stream 
> to be pulling the data straight from the client. I don't see another way to 
> do this.
> 
> I am using org.restlet.ext.fileupload
> 
> thanks!
> 
>     @Post("multipart")
>     public Representation postFiles(Representation entity) {
>         if( entity == null ) {
>                 return fail( Status.CLIENT_ERROR_BAD_REQUEST, 
> "Multipart/form-data required" );
>         }
>         if( ! MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), 
> true) ) {
>                 return fail( Status.CLIENT_ERROR_BAD_REQUEST, 
> "Multipart/form-data required" );
>         }
>         DiskFileItemFactory factory = new DiskFileItemFactory();
>         RestletFileUpload upload = new RestletFileUpload(factory);
>         try {
>                         FileItemIterator fii = upload.getItemIterator(entity);
>                         while( fii.hasNext() ) {
>                                 MessageDigest md = 
> MessageDigest.getInstance("SHA-1");
>                                 FileItemStream fis = fii.next();
>                                 InputStream is = fis.openStream();
> 
>                                 while( true ) {
>                                         byte[] input = new byte[1024];
>                                         int amount = is.read(input);
>                                         if( amount == -1 )
>                                                 break;
>                                         md.update(input, 0, amount);
>                                 }
>                                 is.close();
> 
>                                 byte[] sha1hash = md.digest();
>                                 System.out.println( fis.getFieldName() + " : 
> " + fis.getName() + " : " + byteArray2Hex(sha1hash) );
>                         }
>                 } catch (FileUploadException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>                 } catch (IOException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>                 } catch (NoSuchAlgorithmException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>                 }
>         ....
> 
> -----------------------------
> Bjorn Roche
> http://www.xonami.com
> Audio Collaboration
> http://blog.bjornroche.com
> 
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3016298
> 

-----------------------------
Bjorn Roche
http://www.xonami.com
Audio Collaboration
http://blog.bjornroche.com

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3018872

Reply via email to