I have a call to my documents controller the download action, to serve the client with a downloadable object retrieved from s3. However OpenURI seems to have trouble parsing the url paperclip has stored. This URL is visitable in the browser without any issue, but when attempted to open it in the controller I get a 403 Forbidden error.
documents_controller
def download
data = open(Document.find(params[:id]).upload.url)
send_data data.read, :type => data.content_type, :x_sendfile => true
end
an example url would be
"https://s3.amazonaws.com/mybucket/documents/1/Screen_Shot.png?1372238888"
Error - OpenURI::HTTPError 403 Forbidden shooting up on the first line of the action, when the URL is opened. Any idea what it might be?
A 403 error can occur when the URL is not in string format. Using string interpolation in a similar example for mailing attachments worked for me:
doc = order.document
attachments["Order.pdf"] = File.read(open("#{doc}"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With