Upload files to the root of the bucket

Hi,

I uploaded a file to Amazon S3 and Shrine created a folder with the same name as my bucket, but I don’t want that.

Amazon%20S3

It’s possible to create a folder called “media” in the root of the bucket and upload the files to that folder?

This is what I would like to do:

bucket_name > media > image_file.jpg

Thanks!

Hmm, that’s strange, Shrine shouldn’t be creating that extra directory. Could you reproduce this behaviour in a self-contained Ruby script that I can run? Something like:

require "shrine"
require "shrine/storage/s3"

s3 = Shrine::Storage::S3.new(
  access_key_id:     "...",
  secret_access_key: "...",
  region:            "your-region",
  bucket:            "your-bucket-name",
)

Shrine.storages[:s3] = s3

file = Shrine.upload(StringIO.new, :s3)

# if this doesn't raise an error, it shows the object was uploaded
# in the subdirectory equal to the bucket name
s3.client.head_object(
  bucket: "your-bucket-name",
  key:    "your-bucket-name/#{file.id}",
)

It’s possible to create a folder called “media” in the root of the bucket and upload the files to that folder?

Yes, passing prefix: "media" to Shrine::Storage::S3.new should work.

1 Like

Hi,

The problem was caused because I was adding the endpoint manually in the Shrine::Storage::S3.new data and I added the bucket name in the endpoint. So I removed the endpoint and now it works properly!

Thank you very much!