ActiveStorage에 업로드된 이미지로 자신 앞에 표시할 URL 준비
하고 싶은 일.
WYSIWY 등의 편집을 사용하려면 이미지 URL이 포함된 HTML을 DB에 저장하고 raw로 표시합니다.
문제.
직접'% 1' 을 (를) 저장한 경우, 접속 영패가 만료되고 다음 오류가 발생합니다.
https://storage.googleapis.com/xxx/6qk30zadasnfkansfalksj34gq?GoogleAccessId=...
<Error>
<Code>ExpiredToken</Code>
<Message>The provided token has expired.</Message>
<Details>Request signature expired at: 2020-09-30T19:07:20+00:00</Details>
</Error>
생성을 위한 URL 준비
액세스 토큰이 포함된 서비스URL을 생성하고 표시할 URL을 준비하기 위해 자산용 모델을 제작합니다.
asset.rb
class Asset < ApplicationRecord
has_one_attached :image
end
controller의 Show에 이미지 데이터를 보내는 것으로 변경되었습니다.assets_controller.rb
class AssetsController < ActionController::Base
# GET /assets:id
def show
asset = Asset.find(params[:id])
send_data asset.image.download, filename: asset.image.filename.to_s, content_type: asset.image.content_type
end
end
다음 URL을 DB에 저장하여 적용할 수 있는 서버를 통해 유효기간이 만료되지 않은 상태에서 이미지를 표시합니다....
<img src="http://localhost:3000/assets/2" alt="Image">
...
Reference
이 문제에 관하여(ActiveStorage에 업로드된 이미지로 자신 앞에 표시할 URL 준비), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/wktq/items/a6e9aee89081bd913040텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)