Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: Add request headers to image_tag
    primarykey
    data
    text
    <p><strong>The code:</strong> I got the following piece of code in some HAML file.</p> <pre><code>= image_tag "https://s3.amazonaws.com/my_bucket/my_image.jpg" </code></pre> <p>It sends a request to s3 and loads the image in the browser. I got the following CORS configuration on the bucket:</p> <pre><code>&lt;CORSConfiguration&gt; &lt;CORSRule&gt; &lt;AllowedOrigin&gt;https://www.my_site.com&lt;/AllowedOrigin&gt; &lt;AllowedMethod&gt;GET&lt;/AllowedMethod&gt; &lt;/CORSRule&gt; &lt;/CORSConfiguration&gt; </code></pre> <p><strong>The problerm:</strong> In order to be able to manipulate the images on client side, the images are supposed to be served with the following headers:</p> <pre><code> Access-Control-Allow-Origin: https://www.my_site.com Access-Control-Allow-Methods: GET </code></pre> <p>but this does not happen.</p> <p><strong>The cause:</strong> My browser does not send 'Origin' request header, and therefore s3 does not respond with the desired headers.</p> <p><strong>Why I think that missing "Origin" header is the cause:</strong> Because the response of:</p> <pre><code>wget --server-response --header "Origin:https://www.my_site.com" "https://s3.amazonaws.com/my_bucket/my_image.jpg" </code></pre> <p>is the following:</p> <pre><code> HTTP/1.1 200 OK x-amz-id-2: kQV8HEChV1...QHmHC1Gt/ x-amz-request-id: A626...4A2 Date: Wed, 03 Jul 2013 10:10:38 GMT Access-Control-Allow-Origin: https://www.my_site.com Access-Control-Allow-Methods: GET Access-Control-Allow-Credentials: true Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method ... </code></pre> <p>i.e. the 'Access-Control-Allow-Origin' and 'Access-Control-Allow-Methods' are present.</p> <p><strong>The supposed solution:</strong></p> <p>Is there a way to add manually the desired headers to the image_tag in the HAML file? Something like:</p> <pre><code>= image_tag "https://s3.amazonaws.com/my_bucket/my_image.jpg", :headers=&gt;["Origin"] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload