1

I am trying to do it like this:

AWS.config(
      :access_key_id => '...', 
      :secret_access_key => '...'
    )
    s3 = AWS::S3.new
    bucket_name = 'bucket_name'
key = "#{File.basename(avatar_big)}"
s3.buckets[bucket_name].objects[key].write(:file => avatar_big_path)

This working well for a file, the file is uploaded to the root of the set up bucket.

However, how to upload it into the foloder photos that is located in root?

I've tried

key = "photos/#{File.basename(avatar_big)}"

but this doesn't work.

EDIT: error message enter image description here

Thank you

user984621
  • 46,344
  • 73
  • 224
  • 412

2 Answers2

1

I had the same issue as the OP. This is what worked for me:

key = "photos/example.jpg"
bucket = s3.buckets[bucket_name]
filepath = Pathname.new("path/to/example.jpg")

o = bucket.objects[key]
o.write(filepath)

Something I would check out would be the object key you are trying to use. There's not much documentation on what are the restrictions are (see this and this) but the one shown in error message looks suspicious to me.

Community
  • 1
  • 1
Miguelb
  • 113
  • 1
  • 6
0

Try including the the path in the file key:

 s3.buckets[bucket_name].objects[key].write(:file => "photos/#{avatar_big_path}")
Gotjosh
  • 1,019
  • 4
  • 13
  • 34