Hi Billy,

Your MyApplication has an associated "decoderService" property that will
take care of automatically decoding incoming encoded/zipped representations.
It's enabled by default, nothing else to do!

However, there is no "encoderService" available (yet), that's why you need
to manually use the EncodeRepresentation. There is a related RFE:
http://restlet.tigris.org/issues/show_bug.cgi?id=208

As for the "multi-part" error this is due to the fact that there is no
multi-part client-side support in Restlet (yet). There is a related RFE too:
http://restlet.tigris.org/issues/show_bug.cgi?id=71

In general this is fine because this is generally used from a browser, but
in cases like yours this is a limitation indeed.

Currently you can only send one representation/file/document at a time. If
it's really blocking you, two workarounds:
 - do two separate POSTs instead of one
 - create a Zip archive locally containing your two files and send it using
a normal POST (no need for Restlet FileUpload on the server in this case).

To make your server flexible, you can test the media type of incoming
request's entity:

if(MediaType.MULTIPART_FORM_DATA.equals(request.getEntity().getMediaType()))
{
        // use Restlet FileUpload extension
} else {
        // direclty use the incoming entity
}

In term of documentation we are planning to write some more detailed
documentation (maybe a book) during the end of the year, for the 1.1
release. Currently, there is good coverage in the "RESTful Web Services"
book:
http://www.restlet.org/documentation/books

Best regards,
Jerome  

> -----Message d'origine-----
> De : news [mailto:[EMAIL PROTECTED] De la part de billy
> Envoyé : mardi 10 juillet 2007 13:42
> À : [email protected]
> Objet : Re: How to send files using Restlet
> 
> Hi Thierrry, Jerome:
> 
> I received Thierrry's sample code to put files:
> 
> Component component = new Component();
> component.getServers().add(Protocol.HTTP, 8182);
> 
> component.getDefaultHost().attach("/essai",
>         new MyApplication(component.getContext()));
> component.start();
> 
> /* Launches a simple client */
> FileRepresentation rep = new FileRepresentation(
>         "d:\\temp\\test.txt", MediaType.TEXT_ALL, 0);
> EncodeRepresentation encodedRep = new 
> EncodeRepresentation(Encoding.GZIP,
>         rep);
> Client client = new Client(Protocol.HTTP);
> Response response = 
> client.put("http://localhost:8182/essai/";, encodedRep);
> System.out.println("******" + response.getStatus());
> 
> /* Stops the server */
> component.stop();
> 
> Thanks a lot. The follow-up questions are:
> 1) For the server, is there a way to store the file AND the 
> parameters that 
> the client may send along?
> 2) Does "Encoding.GZIP" mean to zip/compress the file before 
> sending? If yes, 
> why there is no corresponding method for the server to unzip 
> the file? Is 
> the "Encoding" automatically recognized by the server?
> 
> 
> 
> Also, I original had this server code (found in this forum or 
> other related 
> forum) to store files and the parameters that clients may send:
> 
> 
> DiskFileItemFactory factory = new DiskFileItemFactory();
> RestletFileUpload upload = new  RestletFileUpload(factory);
> try
> {
>     List items = upload.parseRequest(request);
>     String xml_text="";
> 
>     //récupérer le xml et l'image
>     int i = 0;
>     for (final Iterator it = items.iterator(); it.hasNext(); ) {    
>         FileItem fi = (FileItem)it.next();
>         
>         File saveTo = new File("c:\\temp\\FileReqReceived" + 
> i + ".txt");
>         fi.write(saveTo);
>         
>         i++;
>     }
> }
> 
> 
> However, I did not know how to send files using Restlet so I 
> used other 
> methods to write the client. I tried to use the above server 
> code to receive 
> file requests sent by using this code:
> 
> FileRepresentation rep = new FileRepresentation(
>         "d:\\temp\\test.txt", MediaType.TEXT_ALL, 0);
> EncodeRepresentation encodedRep = new 
> EncodeRepresentation(Encoding.GZIP,
>         rep);
> Client client = new Client(Protocol.HTTP);
> Response response = 
> client.put("http://localhost:8182/essai/";, encodedRep);
> System.out.println("******" + response.getStatus())
> 
> 
> There was an error:
> 
> the request doesn't contain a multipart/form-data or 
> multipart/mixed stream, 
> content type header is text/*
> 
> It seems that the server is expecting multipart/form-data. 
> How can I modify 
> the server code so that it can receive both 
> multipart/form-data and other 
> types of data?
> 
> I understand lengthy documentation for Restlet may not be 
> available at the 
> moment. What other documents would you recommend so that I 
> can learn from them 
> and then apply the reasoning, coding style etc. when I write 
> develop Restlet 
> applications?
> 
> Regards, billy

Reply via email to