简体   繁体   中英

Uploading to several different s3 buckets with rails and paperclip

I'm running a rails 5 api and am trying to upload photos to link different routes to separate s3 buckets. I have 3 separate buckets that deal with 3 separate routes. There is an avatar bucket that holds avatars. There is a cover bucket that holds cover photos for albums and then there is a photo bucket that holds photos for each album. 3 separate models and controllers on the api.

I have normal paperclip migrations written, but they all go to the same bucket through the env setting in my config/application.rb file using the figaro gem

For simplicities sake,

bucket1: avatar, POST /avatar

bucket2: cover, POST /cover

bucket3: photo, POST /photo

Using paperclip how can I tell the model/controller to upload to that specific bucket?

It's fairly simple! You do it in the has_attached_file setup in the model.

class User < ApplicationRecord
  has_attached_file :avatar, storage: :s3, bucket: "bucket-name"
end

There's a few other ways too - rtfm, https://github.com/thoughtbot/paperclip/blob/b01f47407a03feabd41ac8786b577310e3be87b6/lib/paperclip/storage/s3.rb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM