AWS S3 Query String Request Authentication Alternative Upload a file

By : Maurice
Source: Stackoverflow.com
Question!

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?

By : Maurice


Answers

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,
By : sethu


This video can help you solving your question :)
By: admin