Hi again,
I tested it and I think it works.
The reason to encode (.encode('utf-8')) is that those mime types come from
a database and SQLAlchemy give them to me as unicode, so I have to encode
them. Now I do the same thing but using "latin1" coding instead of "utf-8".
Thanks, Alessandro
León Domingo
Ender - Factoría de Software
[email protected] <[email protected]>
Avda. Cerro del Águila, 7. S23 - 2ª Planta
28703 S.S. de los Reyes (MADRID)
Tlf. 902 01 44 01
<http://www.ender.es/>
<http://www.facebook.com/home.php?#%21/pages/San-Sebastian-de-los-Reyes-Spain/Ender-Factoria-de-Software/142213119143359?ref=ts>
* <http://www.ender.es>*
On 12 October 2012 00:12, Alessandro Molina <[email protected]>wrote:
> mt.encode('utf-8') might end up being wrong, HTTP Headers should only
> be latin1 if I remember correctly.
> Even though, probably, there aren't mime types which contain utf8
> characters.
>
> Also you should be able to use response.content_type =
> 'yourcontenttype' and response.headers['Content-Disposition']=...
> instead of relying on response.headerlist.append, which is a bit
> easier to read and write.
>
>
>
> On Thu, Oct 11, 2012 at 1:51 PM, León Domingo <[email protected]>
> wrote:
> > Hi people,
> >
> > I have this controller method:
> >
> > @expose()
> > def get(self, codigo):
> >
> > aa = dbs.query(ArchivosAsociados).\
> > filter(ArchivosAsociados.codigo == codigo).first()
> >
> > if aa.caducidad and aa.caducidad > dt.datetime.now():
> > content, mt, file_name = SapnsDoc.download(aa.id_recurso)
> > response.headerlist.append(('Content-Type',
> mt.encode('utf-8')))
> > response.headerlist.append(('Content-Disposition',
> > 'attachment;filename=%s' % file_name))
> >
> > return content
> >
> > else:
> > redirect(url('/banco_de_recursos/recurso_caducado/',
> > params=dict(codigo=codigo)))
> >
> > As you can see "mime-type" is "calculated" ("Content-Type" header is
> added
> > dynamically) inside the method. I've read a record from the database
> which
> > gives me the "mime-type" (mt) and "file name" (file_name). Content
> (content)
> > is read from the file itself which is stored in the hard disk.
> >
> > Ok, this thing does not work on IE8 or IE7. Chrome, FF, Opera, Safari or
> > even IE9 do the right thing.
> >
> > Any suggestion?
> >
> > Thanks in advance
> >
> > León
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "TurboGears" group.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/turbogears/-/EIFdY1yODPgJ.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> > http://groups.google.com/group/turbogears?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en.