I was trying to upload files using Aws sdk rails gem.
Everything is successful except I can not find a way how to upload files to a specific folder using ruby sdk.
s3 = Aws::S3::Resource.new
obj = s3.bucket('storagy-teen-dev-us').object("deepak_file")
obj.upload_file('./tmp/aws_test.txt')
This works fine. But I want to create the deepak_file
inside a particular directory in aws bucket, let's say photos
. I already tried the below but not working.
obj = s3.bucket('storagy-teen-dev-us').object("photos/deepak_file")
Try this,
s3 = Aws::S3::Resource.new
path = 'photos/deepak_file/aws_test.txt'
s3.bucket('storagy-teen-dev-us').object(path).upload_file(./tmp/aws_test.txt)
you just need to specify full path of directory with file name.
require 'aws-sdk-s3' # v1.x
client = Aws::S3::Client.new(region: '...',
access_key_id: '...',
secret_access_key: '...')
client.put_object(bucket: bucket,
key: 'photos/my-pic.jpg',
body: File.read(some_image_file),
acl: 'private')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With