简体   繁体   中英

Any thing that is similar to the amazon s3 to store images from rails

I have a page where i store images for each post and i store images in files using paperclip but i want to store it in the amazon s3 instead of storing it in folder. How can i do it?

Let me try to explain it.

  1. add gem 'aws-sdk' to you gemfile. (don't forget to bundle install)

  2. create a new file in {APP FOLDER}/config/s3.yml with the following content: access_key_id: xxxxxYOUR_ACCESS_KEY_IDxxxxx enter code heresecret_access_key: xxxxxYOUR_SECRET_ACCESS_KEYxxxxx

  3. Update your model accordingly:

      has_attached_file :file_field_name, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :url => '/path/tofile/:basename.:extension', :path => '/path/tofile/:basename.:extension', :bucket => 'YOUR_BUCKET' 
  4. At last in your views:

     <div class="field"> <%= f.label :logo, "file_field_name" %> <%= f.file_field :file_field_name %> </div> 

Any issues let me know.

As for the alternatives to S3, Windows Azure Storage and Nimbus.io.

有一个关于它的相当完整的文档在这里 ,一起来看看。

Here is a minimal howto.

For testing and development you can use fake-s3

Descrtiption from github page : "FakeS3 is a lightweight server that responds to the same calls Amazon S3 responds to. It is extremely useful for testing of S3 in a sandbox environment without actually making calls to Amazon, which not only require network, but also cost you precious dollars."

I think you should stay with Amazon S3 in production. I do not know a better alernative. It works.

As per my understanding in Amazon S3 there is nothing called folders to store the data. we have used S3 for string images only but it was stored in the virtual folder S3 termed it as bucket, there are C# API available to read those virtual folders( buckets) information to access the data. there is also AWS SDK available for C#.

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