I suggest you try posting a file without using OAuth; that is using
org.apache.http.client directly. I tried it, and couldn't get it to
work. So there's something tricky about it that I don't understand.
When using OAuth, I suggest you don't send the photo as an OAuth
parameter. Instead, send the photo as the HTTP request body, and send
the OAuth parameters in an Authorization header or URL query string.
net.oauth.client.httpclient4.HttpClient4 will add an InputStreamEntity
to the request object if the method is POST or PUT and the request
OAuthMessage has a body; that is if getBodyAsStream returns an
InputStream (not null). To trigger this behavior you can execute
something like this:
void upload(OAuthClient client, String httpMethod, String url)
throws IOException, OAuthException
{
OAuthMessage response = null;
InputStream input = new FileInputStream("photo.jpg");
try {
OAuthMessage request = new InputStreamMessage(httpMethod,
url, input);
request.getHeaders().add(new OAuth.Parameter("Content-
Type", "image/jpeg"));
response = client.invoke(request,
ParameterStyle.AUTHORIZATION_HEADER);
} finally {
input.close();
}
}
private static class InputStreamMessage extends OAuthMessage
{
InputStreamMessage(String method, String url, InputStream
body) {
super(method, url, null);
this.body = body;
}
private final InputStream body;
@Override
public InputStream getBodyAsStream() throws IOException {
return body;
}
}
On Jan 26, 12:15 pm, Tane Piper <[email protected]> wrote:
> I'm now at the stage that I want to add photo posting to my app,
> however I am having some issues.
>
> I've got the fully qualified path to the file, and I just tried this
> off hand:
>
> params = OAuth.newList("photo[body]", post_message, "photo[photo]",
> filename);
>
> However I didn't expect this to work, all I get is a 500 code back.
>
> I found an example of posting files using standard Java here:
> http://www.anddev.org/solved_http-post_request_to_restful_rails_web-application-t3655.html
> but I cannot find how to add a InputStreamEntity to the parameters and
> how to change the headers to support posting a file.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"OAuth" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/oauth?hl=en
-~----------~----~----~----~------~----~------~--~---