Adding uploaded pictures fro Heroku to AWS S3 Bucket

52 views
Skip to first unread message

David Merrick

unread,
Feb 6, 2019, 11:31:10 PM2/6/19
to Ruby on Rails: Talk
Current errors 500 Internal Server Error and Aws::S3::Errors::AccessDenied

My paperclip.rb in config/initializers is below

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'  # Should this line have instead of this ':s3_domain_url'  this 'mybucketName.s3.amazonaws.com'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

my production.rb in config/environments this code at the end

 config.paperclip_defaults = {
   storage: :s3,
   s3_credentials: {
     bucket: ENV.fetch('S3_BUCKET_NAME'),
     access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
     secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
     s3_region: ENV.fetch('AWS_REGION'),
   }
 }

My pin.rb in models has this code

Class Pin < ApplicationRecord
belongs_to :user
has_attached_file :image, styles: { medium: "300x300#", thumb: "100x100>" }
       validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end

my index.html.erb to view my pins has this code

<%= render 'home/jumbo' unless user_signed_in? %>
<div class = 'center'>
<%= will_paginate @pins%>
</div>
<div id="container" class="transitions-enabled">
<% @pins.each do |pin| %>
<div class='box'>
<div class="panel panel-default">
    <%= link_to image_tag(pin.image.url(:medium)),pin %><br>
    <div class="panel-body">
    <%= pin.description %><br>
    <strong><%= pin.user.name if pin.user %></strong>
</div>
    <%#= link_to 'Show', pin %>
    <% if pin.user == current_user %>
    <div class="panel-footer">
      <%= link_to 'Edit', edit_pin_path(pin) %>
      <%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %>
    </div>
    <% end %>
</div>
</div>
<% end %>
</div>

What else am I missing to connect Heroku to AWS S3 Bucket to upload and store images?

Cheers Dave


Hassan Schroeder

unread,
Feb 7, 2019, 12:07:46 AM2/7/19
to rubyonrails-talk
On Wed, Feb 6, 2019 at 8:31 PM David Merrick <merri...@gmail.com> wrote:
>
> Current errors 500 Internal Server Error and Aws::S3::Errors::AccessDenied

Can you manually upload an image to S3 via the AWS CLI using
those credentials?

Can you view an uploaded image from that bucket in a browser?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

David Merrick

unread,
Feb 7, 2019, 1:49:52 AM2/7/19
to Ruby on Rails: Talk
I can log into my AWS account and can upload images but can't view them. Attached are some screenshots.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yBYDpgVFi%3DpSa5%3Du%2B-tR-md48xkEbdhfj%2BCzTsjEEPOpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Dave Merrick

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merri...@gmail.com

Ph   03 216 2053

Cell 027 3089 169
log2.jpg
log0.jpg
log3.jpg
log1.jpg

Ryan

unread,
Feb 7, 2019, 3:05:26 AM2/7/19
to Ruby on Rails: Talk
Hi David,

Check out this SO article that references S3 bucket permissions. Carrierwave needs to be able to write to the S3 bucket. Ensure your bucket has Put permissions.

David Merrick

unread,
Feb 7, 2019, 3:26:07 AM2/7/19
to Ruby on Rails: Talk
I'm not using carrier wave. I'm using paperclip.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Feb 7, 2019, 8:41:20 AM2/7/19
to rubyonra...@googlegroups.com

> On Feb 7, 2019, at 3:25 AM, David Merrick <merri...@gmail.com> wrote:
>
> I'm not using carrier wave. I'm using paperclip.

Yes, but the same rules apply (on the S3 side) for any attachment system.

Walter
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CA%2B%3DMcKby7nYRSK_3PMMki_qEYHvqc8PR17%3DvQVQiKgShZdeqMg%40mail.gmail.com.

David Merrick

unread,
Feb 7, 2019, 3:12:13 PM2/7/19
to Ruby on Rails: Talk
Hi Once I enable pop ups for aws I can now upload and view images when logged into AWS .

Any suggestions for the bucket?

Cheers Dave



For more options, visit https://groups.google.com/d/optout.

David Merrick

unread,
Feb 7, 2019, 3:16:35 PM2/7/19
to Ruby on Rails: Talk
When  I click on the URL  for the image I get this message

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>8866EFBB969E901F</RequestId>
<HostId>
2E/t/DqGuJMiOcZIaq/WVU8F0KjFRQq91r+bNZz3OWigBEMOczczJ2aFrnHfXn4wQ7E/A7WNPP4=
</HostId>
</Error>

Cheers Dave

On Fri, Feb 8, 2019 at 2:40 AM Walter Lee Davis <wa...@wdstudio.com> wrote:

For more options, visit https://groups.google.com/d/optout.

Hassan Schroeder

unread,
Feb 7, 2019, 4:28:09 PM2/7/19
to rubyonrails-talk
On Thu, Feb 7, 2019 at 12:16 PM David Merrick <merri...@gmail.com> wrote:
>
> When I click on the URL for the image I get this message
>
> <Error>
> <Code>AccessDenied</Code>
> <Message>Access Denied</Message>
> <RequestId>8866EFBB969E901F</RequestId>
> <HostId>
> 2E/t/DqGuJMiOcZIaq/WVU8F0KjFRQq91r+bNZz3OWigBEMOczczJ2aFrnHfXn4wQ7E/A7WNPP4=
> </HostId>
> </Error>

So your bucket isn't configured for public http(s) access; time to dig
into the S3 config...

Good luck!

David Merrick

unread,
Feb 7, 2019, 7:42:27 PM2/7/19
to Ruby on Rails: Talk
Thanks time to read and ask more questions later.

Cheers Dave

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

David Merrick

unread,
Feb 8, 2019, 9:15:37 PM2/8/19
to Ruby on Rails: Talk
I need help setting up a Bucket Policy please. I find this http://awspolicygen.s3.amazonaws.com/policygen.html
to hard to work out.

Cheers Dave


On Fri, Feb 8, 2019 at 10:27 AM Hassan Schroeder <hassan.s...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages