2

Has anyone successfully done this?

My idea is to post to a servlet and it will respond with Query String Request Authentication url after the servlet has authenticated the user. The user will then use this url to upload a picture file.

Was wondering if this is even possible.

The thing I don't get is how do you transfer the picture from your computer or device to the s3.

This is the StringToSign:

PUT\n
(content here?)\n
image/jpeg\n
1175139620\n
/johnsmith/photos/puppy.jpg

How do I inser the content into the string to sign? Do i base64 it first then md-5 it?

1 Answer 1

2

Yes this is very much possible. You will only have to deal with how would like to send the URL back after creating the pre signed URL. Maybe as XML or as plain text..

I would recommend using the jets3t library to create the URL. You could call this API:

org.jets3t.service.S3Service.createSignedPutUrl(String, String, Map, Date, boolean)

You could also an IAM policy instead. But your way is easier.

Edit: Added more information..

That's the beauty of it, when you are using the jets3t library you dont need to any of that. Just call the method :

 S3Service s3Service = new RestS3Service(awsCredentials);
// Create a signed HTTP PUT URL valid for 5 minutes.
   String putUrl = s3Service.createSignedPutUrl(bucket.getName(), object.getKey(),
        object.getMetadataMap(), expiryDate, false);

And use the URL to upload your image like below:

SignedUrlHandler signedUrlHandler = new RestS3Service(null);
S3Object object = new S3Object(bucket,<your file object goes here>);
 S3Object putObject = signedUrlHandler.putObjectWithSignedUrl(putUrl, object);

Edit for signedGetURL():

Only the ones with ProviderCredential being passed in are deprecated.. This one is not :

http://jets3t.s3.amazonaws.com/api/org/jets3t/service/S3Service.html#createSignedGetUrl(java.lang.String, java.lang.String, java.util.Date)

You wouldnt need to pass the credentials into this method anyway. Its only the s3service object that needs the credentials.. like this...

S3Service s3service=new RestS3Service(credentials); // pass your credentials here
String createSignedGetUrl = s3service.createSignedGetUrl(storageObject.getBucketName(),
    storageObject.getKey(),new DateTime().plusMinutes(5).toDate());
Sign up to request clarification or add additional context in comments.

11 Comments

The part I don't get is the StringToSign. Refer to main post added more stuff.
Updated my answer. I am not exactly sure internally how the jets3t library takes care of this. But that's one of the goodness of java isn't it, download a library and call the API's as per the docs.
Ok will look into it. I'm trying to understand how it works if I don't use jets3t.
Hmmm createSignedGetUrl is deprecated any idea what is the equivalent of this?
Thanks!, It all works now. Just for discussion, is there a library equivalent to be used for the iPhone development?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.