validates_attachment_content_type always fails in Internet Explorer 6 and 7

191 views
Skip to first unread message

bobby

unread,
Jul 15, 2008, 2:26:12 AM7/15/08
to Paperclip Plugin
At wit's end trying figure out why Internet Explorer behaves
differently when uploading images using PaperClip
(validates_attachment_content_type always fails). In Firefox, things
work perfectly. The app is hosted on a Linux VPS, Rails 2.0.2, Ruby
1.8.5, latest PaperClip from Github.

If anyone can explain how IE treats files differently, I would be a
happy camper. Do I need to sanitize the filenames in IE?

Here's the code: http://pastie.org/233561

Tom Ward

unread,
Jul 15, 2008, 5:28:33 AM7/15/08
to papercli...@googlegroups.com
On Tue, Jul 15, 2008 at 7:26 AM, bobby <bobby.s...@gmail.com> wrote:
>
> At wit's end trying figure out why Internet Explorer behaves
> differently when uploading images using PaperClip
> (validates_attachment_content_type always fails).

> If anyone can explain how IE treats files differently, I would be a


> happy camper. Do I need to sanitize the filenames in IE?

What content types are being sent by I.E. for each image? In your
create action, debug to find out the value of
params[:friend][:raw_then_photo].content_type to check it is one of
the image types you've specified. If content-type is empty, you may
find it useful to apply this patch I've written for paperclip:

http://github.com/tomafro/paperclip/commit/81e962d54513bc33ce195ca5fc391de683e3db6f

To use it, you would need to register jpeg, png and gif mime-types in
environment.rb or an initializer.

Tom

Jonathan Yurek

unread,
Jul 15, 2008, 9:38:02 AM7/15/08
to papercli...@googlegroups.com
It's possible that IE is sending content types you don't expect, or
that there is extra text on them (I've seen some not be properly
stripped of whitespace and so have an extra \r at the end). Print out
the content_type with inspect so you can see any escaped characters
and you'll know if it's doing something funny.

Actually, let me know what you find. I attempted to strip out extra
characters, but if IE is still making it act funny, I'd very much like
to know.

Thanks, and I hope that helps.

--
Jonathan Yurek
thoughtbot, inc.
jyu...@thoughtbot.com
617.482.1300 x114


Tom Ward

unread,
Jul 15, 2008, 9:59:18 AM7/15/08
to papercli...@googlegroups.com
On Tue, Jul 15, 2008 at 2:38 PM, Jonathan Yurek <jyu...@thoughtbot.com> wrote:
>
> It's possible that IE is sending content types you don't expect, or
> that there is extra text on them (I've seen some not be properly
> stripped of whitespace and so have an extra \r at the end). Print out
> the content_type with inspect so you can see any escaped characters
> and you'll know if it's doing something funny.
>
> Actually, let me know what you find. I attempted to strip out extra
> characters, but if IE is still making it act funny, I'd very much like
> to know.

If you upload jpegs, IE helpfully uses the mime-type 'image/pjpeg',
apparently whether the jpeg is progressive or not. In my tests, PNGs
can be 'image/x-png' too, but GIFs came out as expected: 'image/gif'.
Sounds like a probable cause to me.

Tom

bobby

unread,
Jul 17, 2008, 7:05:04 AM7/17/08
to Paperclip Plugin
Thanks for the tip, Tom, it worked fine. I added the code from your
fork, registered the mime-types, next thing I heard were angels
singing joyously. Incidentally, when I uploaded a .jpg image, IE
submitted it in image/pjpeg format. FF gave the correct image/jpeg
format.

Now to dirty my hands again and actually get the form to display
correctly in IE6/7...

Bobby
Reply all
Reply to author
Forward
0 new messages