rubyonrails+aws(s3)+heroku 사용시 홈페이지에서 이미지파일 업로드 및 출력 문제
조회수 1111회
적용할 페이지 주소는 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
이렇게 설명되어있는데 제 코드에 어떻게 적용해야 할 지 감이 안잡히네요.
질문 요약
그러니까, 업로드 주소를 이용하는 코드를 수정해야 할 것 같은데 어디를 어떻게 해야 할지 모르겠습니다.
제 홈페이지에서 파일을올리면 이미지가 출력이 안되는데, 이미지 주소를 확인해보니
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 %>
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력