Skip to content

the content-type of svg image file is crashed after gzip compressing sync to aws #323

Open

Description

@hothero

I found the error due to the content-type is nil from Mime:type.lookup_by_extension(ext), and I fixed it.
#322

Activity

  1. danielfarrell commented on Apr 21, 2016

    @danielfarrell
    Contributor

    For those who find this later, this seems to be better handled by registering the svg mime type in an initializer:

    Mime::Type.register "image/svg+xml", :svg
    
  2. coneybeare commented on Apr 22, 2016

    @coneybeare

    @danielfarrell This didn't work for me when placed in mime_types.rb. Are you successfully preventing asset_sync from compressing svg's upon upload?

  3. danielfarrell commented on Apr 22, 2016

    @danielfarrell
    Contributor

    I wasn't trying to prevent compression. It should be fine if they are
    compressed as long as the mime type gets set properly on S3. Without this
    the mime type was getting set to application/gzip for me. Maybe we are
    actually after different end results.

    On Friday, April 22, 2016, Matt Coneybeare notifications@github.com wrote:

    @danielfarrell https://github.com/danielfarrell This didn't work for me
    when placed in mime_types.rb. Are you successfully preventing asset_sync
    from compressing svg's upon upload?

    —
    You are receiving this because you were mentioned.
    Reply to this email directly or view it on GitHub
    #323 (comment)

  4. coneybeare commented on Apr 22, 2016

    @coneybeare

    Nope, I was misidentifying the problem. Was set as txt/plain before and your fix made it work, once my cloudfront copy was invalidated (face-palm)

    On Apr 22, 2016, at 6:05 AM, Daniel Farrell notifications@github.com wrote:

    I wasn't trying to prevent compression. It should be fine if they are
    compressed as long as the mime type gets set properly on S3. Without this
    the mime type was getting set to application/gzip for me. Maybe we are
    actually after different end results.

    On Friday, April 22, 2016, Matt Coneybeare notifications@github.com wrote:

    @danielfarrell https://github.com/danielfarrell This didn't work for me
    when placed in mime_types.rb. Are you successfully preventing asset_sync
    from compressing svg's upon upload?

    —
    You are receiving this because you were mentioned.
    Reply to this email directly or view it on GitHub
    #323 (comment)

    —
    You are receiving this because you commented.
    Reply to this email directly or view it on GitHub #323 (comment)

  5. PikachuEXE commented on Apr 25, 2016

    @PikachuEXE
    Member

    @coneybeare
    Do you think #322 is still required?

  6. hothero commented on Apr 25, 2016

    @hothero
    Author

    So we just register Mime::Type "image/svg+xml" and will not get nil from Mime::Type.lookup_by_extension(ext), right?

    If true, maybe readme need to append more advanced usage. But I think #322 still have some use for the future, Mime::Type looks have no all of types.

  7. PikachuEXE commented on Apr 25, 2016

    @PikachuEXE
    Member

    So what is a preferred API for searching mime type?
    ::MIME::Types.type_for or Mime::Type.lookup_by_extension?

  8. coneybeare commented on Apr 25, 2016

    @coneybeare

    I am not familiar enough in this area to have a strong opinion, but I am generally in favor of things that work "out of the box" without any additional manual configuration additions.

  9. PikachuEXE commented on Apr 26, 2016

    @PikachuEXE
    Member

    @coneybeare
    I am fine with that
    But I am not familiarized with that mime types gem

  10. danielfarrell commented on Apr 26, 2016

    @danielfarrell
    Contributor

    Seems to me the best way to handle this is a PR against that gem to add the missing mime types. Anyone have a list of ones that are commonly issues?

  11. PikachuEXE commented on Apr 27, 2016

    @PikachuEXE
    Member

    @danielfarrell
    I am more interested in why the result give by

    • :MIME::Types.type_for
    • Mime::Type.lookup_by_extension
      are different
      I don't know where are these 2 methods documented
      So it could be our usage is incorrect
  12. lloydwatkin commented on Jul 5, 2016

    @lloydwatkin

    I'm seeing the same, my svg files get to cloudfront (AWS CDN) as application/gzip which means they aren't displayed. Work around is png for now, but would prefer svg.

  13. lime commented on Jul 5, 2016

    @lime
    Collaborator

    @lloydwatkin Have you tried the suggestion above to register the right mime type for svg?

    # config/initializers/mime_types.rb
    Mime::Type.register "image/svg+xml", :svg

    Rails recently (5.0) got the above added to the default mime types: rails/rails@7e35cb2

  14. lloydwatkin commented on Jul 5, 2016

    @lloydwatkin

    Yes but it complained it was already defined and I'm on rails 4 at the
    moment. Will investigate when I get a chance. Thanks!
    On 5 Jul 2016 12:38, "Emil Sågfors" notifications@github.com wrote:

    @lloydwatkin https://github.com/lloydwatkin Have you tried the suggestion
    above to register the right mime type for svg?

    config/initializers/mime_types.rbMime::Type.register "image/svg+xml", :svg

    Rails recently got the above added to the default mime types: rails/rails@
    7e35cb2
    rails/rails@7e35cb2
    It's available in 5.0.0.

    —
    You are receiving this because you were mentioned.
    Reply to this email directly, view it on GitHub
    #323 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe/AAQlBu3ebLp5DMCrnfSZeWRIuXs2WQvEks5qSkJRgaJpZM4Hik-t
    .

  15. PikachuEXE commented on Jul 6, 2016

    @PikachuEXE
    Member

    I guess we should let users know they need to put something like
    Mime::Type.register "image/svg+xml", :svg for custom file types
    And also let them know there are some types already registered by rails (and that list might change in the future)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions