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