Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write to a AWS S3 pre-signed url using Ruby

Tags:

ruby

amazon-s3

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.

like image 636
Ariel Voskov Avatar asked May 03 '26 07:05

Ariel Voskov


1 Answers

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
like image 189
Chris Avatar answered May 04 '26 21:05

Chris