Reputation: 303
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?
Upvotes: 0
Views: 370
Reputation: 711
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.
Upvotes: 0
Reputation: 1
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#.
Upvotes: 0
Reputation: 2084
Let me try to explain it.
add gem 'aws-sdk'
to you gemfile. (don't forget to bundle install)
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
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'
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.
Upvotes: 1
Reputation: 13886
There is a fairly thorough documentation about it here, take a look.
Upvotes: 0