Hi all,

I am a novice to Restlet and learning to build something with it. I am using 
Restlet 2.1.2 J2SE package. Now I am stuck with accepting file upload using 
@Put annotation. The following is my code of @Put method.

 private static final String tmp = "/tmp/restlet/";
...
@Put
public String store(Representation entity) throws Exception{
                if(entity == null){
                        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                        return "";
                }
                
                if(!MediaType.MULTIPART_FORM_DATA.equals(entity.getMediaType(), 
true)){
                        setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                        return "";
                }
                
                DiskFileItemFactory factory = new DiskFileItemFactory();
                factory.setSizeThreshold(1024000);
                
                RestletFileUpload upload = new RestletFileUpload(factory);
                
                List items = upload.parseRepresentation(entity);
                
                for(FileItem fi : items){
                        File file = new File(tmp + fi.getName());
                        fi.write(file);
                        System.out.println(fi.getName());
                }
                
                setStatus(Status.SUCCESS_OK);
                return "";
        }
Then I send PUT requests using cURL like these:

 curl -T file.txt http://localhost:8111/
curl -X PUT -T file.txt http://localhost:8111/
curl -X PUT --data @file.txt http://localhost:8111/
but finally got a 400 error. I doubt it is probably the problem of my code but 
not syntax of the cURL command. Basically, the problem is that the parameter, 
entity, could not get the uploading file and is still a null as the code 
proceeds. Is there anyone who has similar experience? Any ideas?


Thanks,
dchampion

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

Reply via email to