简体   繁体   中英

Using Amazon AWS SDK instead of Paperclip for active admin

I am developing an admin panel for a legacy database which has images stored on S3. The way this is done is a full url pointing out to the resource on S3 which is publicly readable.

Paperclip store this in different fields in a database. I need to do these steps.

  • Upload the file to my server
  • Generate a UUID
  • Upload file to S3 with correct permissions and name it with the UUID.
  • Save the complete url in a single db col.

My only requirement is uploading single image file and storing it in a single field as explained. Dont care which lib I use.

My questions are

  • Can I configure paperclip to change its default behaviour to do this?
  • If I use AWS sdk myself do I have to use somekind of threads? I cant see a decent example from where we can use Model to upload image in the same way as done in paperclip.
  • How is the image recieved in model when uploading using paperclip and active admin.

These may be basic questions but I am a ROR newbie! Guidance and help is much appreciated.

Instead of using paperclip I used carrierwave and fog. Which gives the ability to override name and storage location etc.

storage :fog
def initialize(*)
 super
  self.fog_directory    = ENV['S3_BUCKET_NAME']
end

def store_dir
  'pronunciations'
end
def cache_dir
  "#{Rails.root}/tmp/uploads/pronunciations"
end

def extension_white_list
  %w(mp3 m4a)
end

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