3

I want to upload a file to S3 using a pre-signed url

First I create a signed url using url_for(:write)

s3object = S3.buckets['myBucket'].objects['someFolder/testFile.txt']
url = s3object.url_for(:write) #

And I get the url as expected.

https://s3.amazonaws.com/myBucket/someFolder/testFile.txt?AWSAccessKeyId=AKJFGKJASGK......

But now I want to upload something using this url I's assume that there is a way to get an s3 object from that url on which I can use the 'write' method.

Something like obj = getObjectFromUrl(url)

Is there such a method?

If not, how should I use this url to upload something to s3?

EDIT: I probably should explain. I create the URL for testing sake. When I will be working on it, I will only have the URL. Using the URL alone, I will have to upload a file.

Ariel Voskov
  • 326
  • 3
  • 7
  • possible duplicate of [Uploading a file to a S3 Presigned URL](http://stackoverflow.com/questions/23443966/uploading-a-file-to-a-s3-presigned-url) – Uri Agassi May 07 '14 at 15:59

1 Answers1

1

Via the current AWS SDK documentation for Ruby, the suggested method is to simply call read on your s3 object. If you already have the s3 object, you should be able to read directly from the object itself. Also, there is a method for streaming downloads if you wish to stream a file read. AWS S3 Object Documentation

obj.write('abc')
puts obj.read
#=> abc
Chris
  • 788
  • 4
  • 11