You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by P....@albourne.com on 2010/11/12 14:56:23 UTC

tapestry-upload firefox bug

Hi guys,

When using tapestry-upload I stumbled across an unusual browser bug that I spent hours on, so wanted to share... maybe it helps someone else:

Unlike weaker implementations, UploadedFile.getContentType(); returns the mime type of the uploaded file by extracting it from the http header 'Content-Type' after the file posts. To my knowledge this is the best approach... examining the file extension has obvious drawbacks. Unfortunately I found Firefox 3.6.12 sets the header incorrectly on Windows, but correctly on Linux... I am willing to bet some more inconsistent browser implementations exist as well, so be warned that while Tapestry does its part, your code may not work as expected or may contain subtle bugs because browsers can't be trusted to set this header correctly.

I am not sure if some of the tapestry gurus can come up with a better solution, but I work around this problem by combining checks, falling back on a file extension check when I detect a problem... If anyone has a better suggestion I would love to hear it. 

Cheers,
Peter





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-upload firefox bug

Posted by Robert Zeigler <ro...@scazdl.org>.
I recently incorporated mime-util (http://sourceforge.net/projects/mime-util/) into a project of mine that needed reliable mime detection.  It works pretty well and is easily extensible especially for text types.

Robert

On Nov 12, 2010, at 11/127:56 AM , P.Stavrinides@albourne.com wrote:

> Hi guys,
> 
> When using tapestry-upload I stumbled across an unusual browser bug that I spent hours on, so wanted to share... maybe it helps someone else:
> 
> Unlike weaker implementations, UploadedFile.getContentType(); returns the mime type of the uploaded file by extracting it from the http header 'Content-Type' after the file posts. To my knowledge this is the best approach... examining the file extension has obvious drawbacks. Unfortunately I found Firefox 3.6.12 sets the header incorrectly on Windows, but correctly on Linux... I am willing to bet some more inconsistent browser implementations exist as well, so be warned that while Tapestry does its part, your code may not work as expected or may contain subtle bugs because browsers can't be trusted to set this header correctly.
> 
> I am not sure if some of the tapestry gurus can come up with a better solution, but I work around this problem by combining checks, falling back on a file extension check when I detect a problem... If anyone has a better suggestion I would love to hear it. 
> 
> Cheers,
> Peter
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: tapestry-upload firefox bug

Posted by Taha Hafeez <ta...@gmail.com>.
Wondering if The Guru uses @Persist or onActivate/onPassivate to store these
ideas :)

taha


On Fri, Nov 12, 2010 at 11:16 PM, Howard Lewis Ship <hl...@gmail.com>wrote:

> Interesting ... and ugly.  I'm storing this in the back of my mind, along
> with the question: should Ajax URLs be different than standard URLs?
>
> On Fri, Nov 12, 2010 at 5:56 AM, <P....@albourne.com> wrote:
>
> > Hi guys,
> >
> > When using tapestry-upload I stumbled across an unusual browser bug that
> I
> > spent hours on, so wanted to share... maybe it helps someone else:
> >
> > Unlike weaker implementations, UploadedFile.getContentType(); returns the
> > mime type of the uploaded file by extracting it from the http header
> > 'Content-Type' after the file posts. To my knowledge this is the best
> > approach... examining the file extension has obvious drawbacks.
> > Unfortunately I found Firefox 3.6.12 sets the header incorrectly on
> Windows,
> > but correctly on Linux... I am willing to bet some more inconsistent
> browser
> > implementations exist as well, so be warned that while Tapestry does its
> > part, your code may not work as expected or may contain subtle bugs
> because
> > browsers can't be trusted to set this header correctly.
> >
> > I am not sure if some of the tapestry gurus can come up with a better
> > solution, but I work around this problem by combining checks, falling
> back
> > on a file extension check when I detect a problem... If anyone has a
> better
> > suggestion I would love to hear it.
> >
> > Cheers,
> > Peter
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn
> how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>

Re: tapestry-upload firefox bug

Posted by Howard Lewis Ship <hl...@gmail.com>.
Interesting ... and ugly.  I'm storing this in the back of my mind, along
with the question: should Ajax URLs be different than standard URLs?

On Fri, Nov 12, 2010 at 5:56 AM, <P....@albourne.com> wrote:

> Hi guys,
>
> When using tapestry-upload I stumbled across an unusual browser bug that I
> spent hours on, so wanted to share... maybe it helps someone else:
>
> Unlike weaker implementations, UploadedFile.getContentType(); returns the
> mime type of the uploaded file by extracting it from the http header
> 'Content-Type' after the file posts. To my knowledge this is the best
> approach... examining the file extension has obvious drawbacks.
> Unfortunately I found Firefox 3.6.12 sets the header incorrectly on Windows,
> but correctly on Linux... I am willing to bet some more inconsistent browser
> implementations exist as well, so be warned that while Tapestry does its
> part, your code may not work as expected or may contain subtle bugs because
> browsers can't be trusted to set this header correctly.
>
> I am not sure if some of the tapestry gurus can come up with a better
> solution, but I work around this problem by combining checks, falling back
> on a file extension check when I detect a problem... If anyone has a better
> suggestion I would love to hear it.
>
> Cheers,
> Peter
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to learn
how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com