OpenURI :: HTTPError 403 Forbidden - The clip’s public URL for assets stored on S3 (fog)

I have a call for my download action document controller to serve a client with a downloadable object retrieved from s3. However, OpenURI seems to have problems with url clip analysis. This URL is accessible in the browser without any problems, but when I try 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 

url example would be

 "https://s3.amazonaws.com/mybucket/documents/1/Screen_Shot.png?1372238888" 

Error - OpenURI :: HTTPError 403 It is forbidden to fire on the first line of action when the URL is open. Any idea what this could be?

+6
source share
1 answer

Error 403 can occur when the URL is not in string format. Using string interpolation in a similar example for mail attachments working for me:

 doc = order.document attachments["Order.pdf"] = File.read(open("#{doc}")) 
+4
source

Source: https://habr.com/ru/post/948148/


All Articles