Content-Disposition is driving me batty
I have a Python script that transmits a file to the user. An excerpt: if not skipctypeheader: # Set the content type if one is defined for the file ctype = file.getProperty('content_type', d=None) if ctype: RESPONSE.setHeader('Content-Type', ctype) RESPONSE.setHeader('Content-Disposition', 'inline; filename=%s' % filename) We most commonly use this to send PDF reports. After a recent upgrade from Zope 2.8.something to 2.9.3 (on FreeBSD via "ports"), IE users can only sometimes get the file - they otherwise get a blank page. Running 'curl' gives the header values I'd expect: $ curl -vv -O 'http://web2.xrsnet.com/publicstore/download?filename=print.pdf&password=foo' > /dev/null * About to connect() to web2.xrsnet.com port 80 * Trying 10.45.14.64... connected * Connected to web2.xrsnet.com (10.45.14.64) port 80
GET /publicstore/download?filename=print.pdf&password=foo HTTP/1.1 User-Agent: curl/7.15.1 (i486-pc-linux-gnu) libcurl/7.15.1 OpenSSL/0.9.8a zlib/1.2.3 libidn/0.5.18 Host: web2.xrsnet.com Accept: */*
< HTTP/1.1 200 OK < Date: Wed, 16 Aug 2006 22:26:11 GMT < Server: Zope/(Zope 2.9.3-, python 2.4.3, freebsd6) ZServer/1.1 < Content-Length: 1742 < Content-Type: application/pdf; charset=iso-8859-15 < Content-Disposition: inline; filename=print.pdf < Vary: User-Agent % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1742 100 1742 0 0 30301 0 --:--:-- --:--:-- --:--:-- 0* Connection #0 to host web2.xrsnet.com left intact * Closing connection #0 Would some IE users please let me know whether they can view this PDF normally? http://web2.xrsnet.com/publicstore/download?filename=print.pdf&password=foo Any speculation about what might be causing this is extremely welcome. I'm *not* looking forward to rolling back to 2.8.x (and Python 2.3) at this point. -- Kirk Strauser The Day Companies
--On 16. August 2006 17:28:00 -0500 Kirk Strauser <kirk@daycos.com> wrote:
I have a Python script that transmits a file to the user. An excerpt:
if not skipctypeheader: # Set the content type if one is defined for the file ctype = file.getProperty('content_type', d=None) if ctype: RESPONSE.setHeader('Content-Type', ctype)
RESPONSE.setHeader('Content-Disposition', 'inline; filename=%s' % filename)
I remember having had similar problems with IE and downloading files. In general we use only content-disposition: attachment for IE vs. content-disposition: inline for all other browsers. After that change we haven't had any bug reports from IE users. -aj
Andreas Jung wrote:
--On 16. August 2006 17:28:00 -0500 Kirk Strauser <kirk@daycos.com> wrote:
I have a Python script that transmits a file to the user. An excerpt:
if not skipctypeheader: # Set the content type if one is defined for the file ctype = file.getProperty('content_type', d=None) if ctype: RESPONSE.setHeader('Content-Type', ctype)
RESPONSE.setHeader('Content-Disposition', 'inline; filename=%s' % filename)
I remember having had similar problems with IE and downloading files. In general we use only content-disposition: attachment for IE vs. content-disposition: inline for all other browsers. After that change we haven't had any bug reports from IE users.
-aj
I had similar problems too. This seems to work with IE: theFile=open( self.pdfpath,'rb') result = theFile.read() .... RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader("Content-Disposition","filename=report.pdf") RESPONSE.setHeader('Content-Length',len(result)) RESPONSE.write(result) David
On Thursday 17 August 2006 10:55 am, David H wrote:
I had similar problems too. This seems to work with IE: theFile=open( self.pdfpath,'rb') result = theFile.read() .... RESPONSE.setHeader('Content-Type','application/pdf') RESPONSE.setHeader("Content-Disposition","filename=report.pdf") RESPONSE.setHeader('Content-Length',len(result)) RESPONSE.write(result)
Sending the "Content-Length" header fixed the problem. PDFs now appear inline and with their expected contents. I haven't diffed the code between 2.8 and 2.9, but I'm guessing that Zope used to send that header by default but no longer does. -- Kirk Strauser The Day Companies
Would some IE users please let me know whether they can view this PDF normally?
http://web2.xrsnet.com/publicstore/download?filename=print.pdf&password=foo
Any speculation about what might be causing this is extremely welcome. I'm *not* looking forward to rolling back to 2.8.x (and Python 2.3) at this point.
I am running IE7 beta 3 -- on my machine the pdf file seems to load -- so no content disposition problem but there are messages about missing fonts from the PDF reader *7.0.8 btw) -- no real information is displayed so I am guessing this is "abnormal" by your definition.
On Thursday 17 August 2006 9:54 am, Brian Sullivan wrote:
I am running IE7 beta 3 -- on my machine the pdf file seems to load -- so no content disposition problem but there are messages about missing fonts from the PDF reader *7.0.8 btw) -- no real information is displayed so I am guessing this is "abnormal" by your definition.
Nuts. I was trying to generate a "clean" PDF for testing purposes but looks like it didn't work. I re-uploaded the test file (same URL) with Times New Roman and embedded fonts. -- Kirk Strauser The Day Companies
On 8/17/06, Kirk Strauser <kirk@daycos.com> wrote:
Nuts. I was trying to generate a "clean" PDF for testing purposes but looks like it didn't work. I re-uploaded the test file (same URL) with Times New Roman and embedded fonts.
OK -- that seems to be more what I would call normal. I see the page with "This is a test" in Adobe reader -- but also a page/tab is created that is blank. Is that the problem?
On Thursday 17 August 2006 11:02 am, Brian Sullivan wrote:
OK -- that seems to be more what I would call normal. I see the page with "This is a test" in Adobe reader -- but also a page/tab is created that is blank. Is that the problem?
Nope - customers are actually getting a single blank page and nothing else. We could live with a blank tab if that was the only problem. -- Kirk Strauser The Day Companies
On 8/17/06, Kirk Strauser <kirk@daycos.com> wrote:
On Thursday 17 August 2006 11:02 am, Brian Sullivan wrote:
OK -- that seems to be more what I would call normal. I see the page with "This is a test" in Adobe reader -- but also a page/tab is created that is blank. Is that the problem?
Nope - customers are actually getting a single blank page and nothing else. We could live with a blank tab if that was the only problem.
It looks like you have changed to remove the Content-Disposition header? Now it comes up "inline" (I guess the default?).
On Thursday 17 August 2006 11:24 am, Brian Sullivan wrote:
It looks like you have changed to remove the Content-Disposition header?
Now it comes up "inline" (I guess the default?).
No, it's still there (and still set to "inline"). I did, however, follow David H's advice to add the Content-Length header. Preliminary tests are very promising. -- Kirk Strauser The Day Companies
Kirk Strauser wrote at 2006-8-16 17:28 -0500:
I have a Python script that transmits a file to the user. An excerpt:
if not skipctypeheader: # Set the content type if one is defined for the file ctype = file.getProperty('content_type', d=None) if ctype: RESPONSE.setHeader('Content-Type', ctype)
RESPONSE.setHeader('Content-Disposition', 'inline; filename=%s' % filename) .... < HTTP/1.1 200 OK < Date: Wed, 16 Aug 2006 22:26:11 GMT < Server: Zope/(Zope 2.9.3-, python 2.4.3, freebsd6) ZServer/1.1 < Content-Length: 1742
Your PDF file appears to be small. I am also surprised that in your earlier post you returned the "File" object itself. I would rather expect "str(fileObject.data)". -- Dieter
On Thursday 17 August 2006 1:28 pm, Dieter Maurer wrote:
Your PDF file appears to be small.
It was pretty dinky earlier (a single line of text).
I am also surprised that in your earlier post you returned the "File" object itself. I would rather expect "str(fileObject.data)".
Without looking at the source, I'm guessing that ExtFile.__repr__ just calls str() anyway. -- Kirk Strauser The Day Companies
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dieter Maurer wrote:
Kirk Strauser wrote at 2006-8-16 17:28 -0500:
I have a Python script that transmits a file to the user. An excerpt:
if not skipctypeheader: # Set the content type if one is defined for the file ctype = file.getProperty('content_type', d=None) if ctype: RESPONSE.setHeader('Content-Type', ctype)
RESPONSE.setHeader('Content-Disposition', 'inline; filename=%s' % filename) .... < HTTP/1.1 200 OK < Date: Wed, 16 Aug 2006 22:26:11 GMT < Server: Zope/(Zope 2.9.3-, python 2.4.3, freebsd6) ZServer/1.1 < Content-Length: 1742
Your PDF file appears to be small.
I am also surprised that in your earlier post you returned the "File" object itself. I would rather expect "str(fileObject.data)".
That would defeat the "stream iterator" optimimzation, wouldn't it? Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFE5UQy+gerLs4ltQ4RAiglAJ4x7yj4Bbjv3kdZQTh+wGu04mrK4QCfdQ6u ZDkFQsOnTNLXZXSwK/TTyds= =AtDI -----END PGP SIGNATURE-----
participants (6)
-
Andreas Jung -
Brian Sullivan -
David H -
Dieter Maurer -
Kirk Strauser -
Tres Seaver