Paperclip photo upload fails in IE8
Asked Answered
G

3

7

I'm using paperclip to upload image in my app. The validation I've is :

 validates_attachment_content_type :image, :content_type => ['image/jpg','image/jpeg', 'image/png', 'image/tiff', 'image/gif']

Everything works well in firefox, chorme and IE9. But in IE8, I get an error - "Photos image content type Invalid format !!!"

Any solution or clue is much appreciated.

Gelman answered 27/6, 2011 at 3:52 Comment(0)
P
12

says it needs extra image format image/pjpeg in content type i.e. :content_type => ['image/pjpeg']

Below will be helpful for sure.

http://blog.joshsoftware.com/2010/11/26/paperclip-validates_attachment_content_type-always-fails-in-ie-6-and-7-for-jepg-and-png-image/

http://blog.siyelo.com/tip-of-the-day-mime-types-for-paperclip-ie8

Parvis answered 27/6, 2011 at 8:32 Comment(0)
L
2

You can try this instead: content_type => /image/

Lazes answered 27/6, 2011 at 4:1 Comment(1)
Hi Codeglot, as you suggested I did this : validates_attachment_content_type :image, :content_type => ['/image/jpg','/image/jpeg', '/image/png', '/image/tiff', '/image/gif']. But now the photo upload does not work in any browser. Did I missed anything?Gelman
K
1

I think you may have misunderstood the previous answer. What he was suggesting was that you use a regular expression on containing the word 'image' instead of adding the forward slash in the front. So your modified code would look like this:

validates_attachment_content_type :image, :content_type => /image/

The // means you are using a regular expression for the content type instead of being explicit by each element in the array. The above would search the whole content_type string and match image, or you can be a little more strict and use:

validates_attachment_content_type :image, :content_type => /^image/

which means that the string has to begin with the word 'image', which it should. This should help you through IE as well.

Keyser answered 27/6, 2011 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.