[albatross-users] Exporting non text/html ContentType

Francis Meyvis francis.meyvis at sonycom.com
Wed Jul 30 20:49:38 EST 2003


Hello,

I'm using Albatross as a cgi-bin framework
for users to store excel documents on a server,
parse the documents on the server and place
the extracted data in a database.
The extracted data can be viewed in regular html pages.
In addition the user can export this extracted data and
the excel document later in another contenttype
(e.g. application/vnd.ms-excel or some plain text).
All goes over https with the Apache server.

This all works well for most common browsers except for MS IE.
On the net I already found mentioning that Apache mod-ssl
and MS IE go not well together. There are some specific
configurations to apply to mod-ssl that provide a
workaround for this defect in MS IE.
Still it does not work correctly.

Our Apache administrator did place an excel file
together in the directory with the regular html files and
so he proved that Apache, without albatross inbetween
serves this document correctly over https.
Note that MS IE does serve all correctly if it goes
over http:// (so no https://)

The error message I get is something like this:
"""
Internet Explorer cannot download hdb.cgi from host.
Internet Explorer was not able to open this internet site.
The requested site is either unavailable or cannot be found.
Please try agian later.
"""

So the only thing I can imagine is that I do something wrong
with the on the fly generated specific headers or content
I wonder whether any of you ran in the same problem already and
can point me to the error in my code?
Or can locate the error in some other place and
give some workaround that does the job ...

I'm use albatross v1.01 (on Redhat, debian and SuSE
but the fix on Redhat is most welcomed).

I extended SessionFileAppContext with these methods

      [... snippet ... ]
      def write_headers(s):
          if not s.msContentType:
              SessionFileAppContext.write_headers(s)
          else:
              # No cookie?  SessionFileContextMixin.write_headers(self)
              s.request.write_header("Pragma", "no-cache")
              s.request.write_header("Content-Type", s.msContentType)
              if s.miContentSize:
                  s.request.write_header("Content-Disposition",
                                         "attachement; filename=%s; size=%d" % \
                                         (s.msContentDisposition, s.miContentSize))
              else:
                  s.request.write_header("Content-Disposition",
                                         "attachement; filename=%s" % \
                                         (s.msContentDisposition))


      def setHttpHeaders(s, asContentType, asContentDisposition, aiContentSize = None):
          s.msContentType = asContentType
          s.msContentDisposition = asContentDisposition
          s.miContentSize = aiContentSize


      def resetHttpHeaders(s):
          s.msContentType = None
      [... snippet ...]

Writing out the non text/html content goes like this
In the page_process I do this
(for exporting as a text, I set the content type to hdb/hdb
instead of text/text because some browsers otherwise
try to render it instead of opening the save as dialog button)

      [... snippet ...]
      aoCtx.setHttpHeaders("hdb/hdb",
                           "prjExport%s.txt" % time.strftime("%y%m%d%H%M%S"))
      [... snippet ...]

In the page_display this is what happens:

     def StripNone(s):
         if None == s: return ""
         else: return s


      [... snippet ...]
          from hdb import exporter
          voExporter = exporter.cExporterPrj(
              vlPrj, aoCtx.getVar(aoCtx.msFrmtExportComma))

          import string
          try:
              while 1:
                  aoCtx.write_content(
                      string.join(
                          map(str, map(StripNone, voExporter.getRowLabelled())),
                          '\t'))
                  aoCtx.write_content('\n')
                  aoCtx.flush_content()
          except exporter.cExporterEndofRow:
              pass
      [... snippet ...]

Thanks,
francis




More information about the Albatross-users mailing list