Hi Eben,

It looks that you could simplify your code significantly. Representation has
"downloadName" and "mediaType" properties that you could use instead of
manually playing with HTTP headers. See:

"Mapping HTTP semantics"
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/130-restlet.html

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com




-----Message d'origine-----
De : Eben [mailto:ebe...@gmail.com] 
Envoyé : vendredi 25 septembre 2009 03:08
À : discuss@restlet.tigris.org
Objet : trouble with client-side of Restlet Connector PUT'ing files in
versions later than 1.1-M4

Hello,

So I have a Restlet connector question.  A colleague of mine was
having trouble with the following code.  The code works fine with the
1.1-M4 version (which was what was being used at the time of
development) of the Restlet connector, but not with more recent
versions.  Perhaps the code is not quite entirely agreeable with more
recent versions of Restlet?  Any suggestions?

The code in question is appended below.  I can provide additional
details if necessary, though I will have to ask the 3rd party for
them.

What we see on the server side is the client (code below) stops
writing to the stream prematurely or not at all.

If I attempt to call the server using CURL it works fine.

Thanks,
  Eben Calhoun

// attachmentId is just an integer.
Reference referenceforUpload = new
Reference("http://localhost:8080/restApp/attachment/"; + attachmentId);
        
FileInputStream fis = null;
fis = new FileInputStream(fileupload);

InputRepresentation entity = new InputRepresentation(
    fis,
    MediaType.valueOf(fileuploadContentType),
    fileupload.length());

Request requestforUpload = new Request(Method.PUT,
    referenceforUpload);
requestforUpload.setChallengeResponse(authentication);

Object headers =
requestforUpload.getAttributes().get("org.restlet.http.headers");

Form requestHeaders = (Form) requestforUpload.getAttributes().get(
    "org.restlet.http.headers");

if (requestHeaders == null) {
    requestHeaders = new Form();
    requestforUpload.getAttributes().put(
        "org.restlet.http.headers",
        requestHeaders);
}

requestHeaders.add("content-type", fileuploadContentType);
// FILENAME is just a String with the name of the file as provided by
a web browser upstream
// ATTACHMENT is the 'fileUploadContentType' as provided by a web
browser upstream
requestHeaders.add("content-disposition", ATTACHMENT + ";" + FILENAME
+ "=" + "\""
    + fileuploadFileName + "\"");


requestforUpload.setEntity(entity);

Client restClientforattachmentUpload = null;

restClientforattachmentUpload = new Client(Protocol.HTTPS);
Response responseforUpload =
restClientforattachmentUpload.handle(requestforUpload);

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

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

Reply via email to