Skip to content

Troubles with SVGs on AWS (again) #794

@brian-kephart

Description

@brian-kephart

Recap:

Now, I find that even though files upload correctly, Amazon S3 does not supply the correct Content-Type header for SVG files. This makes them unusable in <img> tags.

There is an option to suppy a Content-Type when uploading to S3. I can make it work using two hooks, like so:

def on_uploader(args)
  args[:aws_settings][:aws_file_upload_settings] = lambda { |settings|
    @suppress_content_type ||= false
    settings[:content_type]  = params.dig("file_upload")&.content_type unless @suppress_content_type
    settings
  }
end

# This is needed to prevent using 'svg+xml' content type being applied to resized images, which are JPGs
def uploader_aws_before_upload(_args)
  @suppress_content_type = true unless _args[:key].match? /\.svgz?\z/
end

But that still leaves SVG use through AWS not working by default. Plus, if SVGs need a Content-Type applied when uploading to S3, it seems likely that some other file types will need one as well. I think this option should be passed by default.

Since my last two PRs about this haven't completely solved the problem, I'm filing this issue to get comments before attempting another one. Any thoughts on how this should be handled?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions