Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hothero opened this issue Feb 25, 2016 · 15 comments

Comments

@hothero
Copy link

hothero commented Feb 25, 2016

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

@danielfarrell
Copy link
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

@coneybeare
Copy link

@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?

@danielfarrell
Copy link
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 [email protected] 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)

@coneybeare
Copy link

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 [email protected] 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 [email protected] 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)

@PikachuEXE
Copy link
Member

@coneybeare
Do you think #322 is still required?

@hothero
Copy link
Author

hothero commented Apr 25, 2016

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.

@PikachuEXE
Copy link
Member

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

@coneybeare
Copy link

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.

@PikachuEXE
Copy link
Member

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

@danielfarrell
Copy link
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?

@PikachuEXE
Copy link
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

@lloydwatkin
Copy link

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.

@lime
Copy link
Collaborator

lime commented Jul 5, 2016

@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

@lloydwatkin
Copy link

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" [email protected] 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
.

@PikachuEXE
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants