redactor-rails icon indicating copy to clipboard operation
redactor-rails copied to clipboard

Dealing with signed URLs

Open artem-mindrov opened this issue 11 years ago • 1 comments

I'm using a private S3 bucket to store uploads, so Fog generates signed URLs for all assets. The problem is that those URLs are saved into the HTML body so I get a 403 against all embedded images when the request expires. I'm wondering what the best way to deal with this would be.

Thanks

artem-mindrov avatar May 23 '13 12:05 artem-mindrov

It's been a while since I've worked on this last. I solved it by adding this method to the model:

  def notes_with_signed_urls
    content = notes

    Nokogiri::HTML(notes).xpath("//img").each do |img|
      img = img.to_html
      asset_id = img[/pictures\/([0-9]*)\//].split("/").last
      content.gsub!(img, ActionController::Base.helpers.image_tag(RedactorRails::Picture.find(asset_id).url))
    end

    content
  end

artem-mindrov avatar Jan 24 '14 05:01 artem-mindrov