<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eugene Melnic on Medium]]></title>
        <description><![CDATA[Stories by Eugene Melnic on Medium]]></description>
        <link>https://medium.com/@melnic404?source=rss-3ff148ef6f87------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CP-CwAHroS_rELHMsiwHYg.jpeg</url>
            <title>Stories by Eugene Melnic on Medium</title>
            <link>https://medium.com/@melnic404?source=rss-3ff148ef6f87------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:56:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@melnic404/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Do you care about ContentDisposition header in ActiveStorage?]]></title>
            <link>https://medium.com/@melnic404/do-you-care-about-contentdisposition-header-in-activestorage-031f89d75cd2?source=rss-3ff148ef6f87------2</link>
            <guid isPermaLink="false">https://medium.com/p/031f89d75cd2</guid>
            <category><![CDATA[download]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[active-storage]]></category>
            <category><![CDATA[inline]]></category>
            <category><![CDATA[aws-s3]]></category>
            <dc:creator><![CDATA[Eugene Melnic]]></dc:creator>
            <pubDate>Thu, 25 Sep 2025 19:29:20 GMT</pubDate>
            <atom:updated>2025-09-29T17:23:37.373Z</atom:updated>
            <content:encoded><![CDATA[<h3>Do you care about Content Disposition header in Active Storage?</h3><p>Recently, I ran into an interesting problem:<br>Some of the PDF files on my work project’s website opened directly in the browser (inline), while others were downloaded.</p><p>The project itself is pretty old, it had started with Rails 5 and was upgraded to 6 and then 7 version over last 8 years. Somewhere along the way, some configuration got out of sync.</p><h4>Check Rails configuration</h4><p>Rails has a setting for which file types can be shown inline:</p><pre>config.active_storage.content_types_allowed_inline = [<br> “image/png”,<br> “image/jpeg”,<br> “image/gif”,<br> “image/webp”,<br> “application/pdf”<br>]</pre><p>After upgrading to Rails 7, I made sure application/pdf was added to this list.</p><h4>What about S3?</h4><p>In our case, files are stored in public AWS S3 bucket. We don’t proxy files through Rails with `rails_blob_path` or redirects. Instead, customers get a direct link to the file on S3 or Cloudfront CDN depending on our needs.</p><p>At first, my idea was simple - use Rails helper like this:</p><pre>rails_blob_path(attachment, disposition: “inline”)</pre><p>But this only works if the file doesn’t already have a <strong>Content-Disposition: attachment</strong> header set in S3 metadata (Interesting fact that this header is set as System). And of course, a lot of old files had it.</p><p>So even with the Rails config fixed, the browser was still forcing downloads.</p><h4>Debug</h4><p>Before changing anything, it’s useful to check what headers a file has:</p><pre>s3 = Aws::S3::Client.new(<br> region: “your-region”<br> access_key_id: ENV[“AWS_ACCESS_KEY_ID”],<br> secret_access_key: ENV[“AWS_SECRET_ACCESS_KEY”]<br>)<br><br>bucket = &quot;your_bucket_name&quot;<br>key = &quot;your_file_key&quot;<br><br>response = s3.head_object(bucket: bucket, key: key)<br>response.content_disposition</pre><p>If you see <strong>attachment</strong>, that’s the reason your PDF is being downloaded.</p><h4>Fixing old files</h4><p>Unfortunately, you can’t just update metadata in place on S3.<br>The trick is to copy the file onto itself with updated metadata:</p><pre>resp = s3.head_object(bucket: bucket, key: key)<br><br>s3.copy_object(<br> bucket: bucket,<br> key: key,<br> copy_source: &quot;#{bucket}/#{key}&quot;,<br> metadata_directive: &#39;REPLACE&#39;,<br> content_type: resp.content_type,<br> content_disposition: nil, # remove &quot;attachment&quot;<br> metadata: resp.metadata # keep custom metadata<br>)<br><br>response = s3.head_object(bucket: bucket, key: key)<br>response.content_disposition</pre><p>Now the file doesn’t force download anymore. Browsers will open it inline.</p><p>Once <strong>content_types_allowed_inline</strong> is configured correctly, and old files are fixed, all new uploads will work fine too.</p><p>That’s it. Now, your users will see PDFs open directly in their browser instead of automatically downloading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=031f89d75cd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>