rubyonrails+aws(s3)+heroku 사용시 홈페이지에서 이미지파일 업로드 및 출력 문제

조회수 1110회

적용할 페이지 주소는 http://practicerails5.herokuapp.com/ 이거구요

제 github 주소입니다 https://github.com/jnhn333/jnhn.github.com

https://rorlab.gitbooks.io/railsguidebook/content/appendices/aws_s3.html 를 따라해봤습니다.

$gem 'carrierwave-aws'
$bundle install

후에

config/initializers/ 에 carrierwave.rb 파일이 없어
carrierwave.rb를 만들어서 다음과 같이 작성했습니다.
CarrierWave.configure do |config|
  config.storage    = :aws
  config.aws_bucket = ENV['using-heroku']
  config.aws_acl    = :public_read
  config.asset_host = 'https://using-heroku.s3-ap-northeast-1.amazonaws.com/'
  config.aws_authenticated_url_expiration = 60 * 60 * 24 * 365

  config.aws_credentials = {
    access_key_id:     ENV['저의 아이디'],
    secret_access_key: ENV['저의 키']
  }
end if Rails.env == 'production'
$ heroku config:set S3_BUCKET_NAME=저의 버킷 네임
$ heroku config:set AWS_ACCESS_KEY_ID=저의 아이디
$ heroku config:set AWS_SECRET_ACCESS_KEY=저의 키

이렇게 입력했구요 이렇게만 하면 끝인가요?

그리고 마지막에

https://rorlab.gitbooks.io/railsguidebook/content/appendices/aws_s3.html 마지막부분

그리고 파일 업로드 클래스 파일에 아래와 같이 storage 옵션 조건을 추가한다.
if Rails.env == 'production'
  storage :aws
else
  storage :file
end

이렇게 설명되어있는데 제 코드에 어떻게 적용해야 할 지 감이 안잡히네요.

질문 요약

  1. 그러니까, 업로드 주소를 이용하는 코드를 수정해야 할 것 같은데 어디를 어떻게 해야 할지 모르겠습니다.

  2. 제 홈페이지에서 파일을올리면 이미지가 출력이 안되는데, 이미지 주소를 확인해보니

thumbnail

https://s3-ap-northeast-1.amazonaws.com/using-heroku/uploads/user/avatar/7/thumb_watcha_icon_200x200_new.png 

postimage

https://s3-ap-northeast-1.amazonaws.com/using-heroku/uploads/post/image/8/watcha_icon_200x200_new.png
---------------------------------------------------------------------------------------------------------------------------------------
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>PermanentRedirect</Code>
<Message>
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
</Message>
<Bucket>using-heroku</Bucket>
<Endpoint>using-heroku.s3.ap-northeast-2.amazonaws.com</Endpoint>
<RequestId>B8CBA7DB5CE50684</RequestId>
<HostId>
MGxeldF/tVY8oyHQMNobbyIM1Zk6STURHGkEsejsVshwt4im+6yP+YaYdK494KRulMubDEh4AAc=
</HostId>
</Error>

이렇게 되있더라구요. 왜그런걸까요? (버킷에는 업로드가 됩니다. 페이지에 표현이 안되네요)

페이지에 표현되는 코드라서 변경해야 할 코드(제생각)

_post.html.erb

thumbnail 태그1
         <img src="<%= current_user.avatar.url %>" />

thumbnail 태그2
        <% if post.user.avatar %>
            <img class="circle thumbnail" src="<%= post.user.avatar.thumb.url %> ">
        <% end %>

image 태그
        <% if post.image.url %>
            <img src="<%= post.image.url %>">
        <% end %>

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • aws 문제로 포기했습니다... 알 수 없는 사용자 2017.6.16 15:26
  • rails 에서 aws s3에 파일을 업로드하는 방법은 carrierwave와 fog를 함께 사용해서 하시는 방법이 간단하고 일반적입니다. carrierwave gem wiki에서 fog를 검색해서 사용하시면 될 것 같습니다. # storage :fog라고 되어 있는 부분의 주석을 푸시고 :file 부분을 주석처리 해주세요. 우연 2017.7.24 04:42

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)