views:

137

answers:

2

Hi

I am trying to upload files to Amazon S3 from Google App Engine (in Java) using the URLFetchService, but I am not getting very far. For a start I have never done any REST programming before, nor GAE.

I have looked through the documentation for S3, and have come up with the following code. Am I going along the right path?

final URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
final URL url = new URL("http", AWS_BUCKET+".s3.amazonaws.com/myFile.jpg", "");
final HTTPRequest request = new HTTPRequest(url, HTTPMethod.PUT, followRedirects());
request.addHeader(new HTTPHeader("Content-Type", contentType));
request.addHeader(new HTTPHeader("Content-Length", Integer.toString(pictureBytes.length)));
request.addHeader(new HTTPHeader("Expect", "100-continue"));
request.addHeader(new HTTPHeader("Authorization", "AWS "+AWS_ACCESS_KEY+":"+AWS_SECRET_KEY));
request.setPayload(pictureBytes);
urlFetchService.fetch(request);

When I run the above code, I get Entity enclosing requests cannot be redirected without user intervention as an error message.

Thanks in advance for any hints/tips/pointers/URLs/solutions :)

Cheers

Rich

A: 

Ok, after all that, the sample code from Amazon themselves works just fine! I wish there was a blush emoticon that worked in SO because I need it.

I wasn't expecting the Amazon code to work because of the sandbox that GAE/J runs in, but I should've tested it first.

Thanks again

Rich

Rich
A: 

Can you post the Sample Code? I can't find it in Amazons reference.

Big thanks!