Stuffing file objects into my objects
I have no concrete idea of what I'm doing, but I've managed to get pretty far... I have a product class that has an attribute that is an OFS.Image.File object. I have setter and getter methods called setFile() and getFile(), respectively. So far I can upload files and they get stored into my product, and I can even get the File objects out (via scripting). But what I'm not sure how to do is to access the file objects via a web path. Something to the effect of /stuff/product_instance/getFile. At this point /stuff/product_instance/getFile almost works. It works fine with images, text files, pdf on the Mac... But word documents don't seem to work, as if the content-type isn't being recognized by the browser on the download, i.e. Word docs are rendered as text files in the browser window. I have had this problem before, but my solution was to attach a file precondition that set some response headers: hdr_name = "content-disposition" hdr_value = 'attachment; filename="%s"' % filename context.REQUEST.RESPONSE.setHeader( hdr_name, hdr_value ) But now I have the File object embedded inside another object. How could I attach a precondition that would get called if the file is accessed via /stuff/product_instance/getFile? When I tried passing the name of an external script to the File constructor, but that doesn't seem to get called. Any ideas or help? Damon.
Damon Eckhoff writes:
... At this point /stuff/product_instance/getFile almost works. It works fine with images, text files, pdf on the Mac... But word documents don't seem to work, as if the content-type isn't being recognized by the browser on the download, i.e. Word docs are rendered as text files in the browser window. I have had this problem before, but my solution was to attach a file precondition that set some response headers: The easiest solution is to use an attribute for your file object, say "file". Then, you can simply use "<url_to_your_instance>/file".
The next easiest solution is a method "viewFile" that uses "getFile" to locate the file object and then calls its "index_html". Dieter
On 6/13/02 2:07 PM, "Dieter Maurer" <dieter@handshake.de> wrote:
The easiest solution is to use an attribute for your file object, say "file". Then, you can simply use "<url_to_your_instance>/file".
The next easiest solution is a method "viewFile" that uses "getFile" to locate the file object and then calls its "index_html".
Dieter, I appreciate the help... Okay, I created the viewFile method: def viewFile( self, REQUEST=None ): "Views the file" self._file.index_html( REQUEST, REQUEST.RESPONSE) So, when I access it via /instance/viewFile, the precondition does get called, but the browser just sits and spins never to display the file or prompt for a download. Am I not passing the correct response object in?
From the looks of Image.File.index_html, it should handle everything, right?
Also, to clarify, is there anything special that I have to do to make the object an attribute. Right now it is stored in <instance>._file. Again, I appreciate the help as I wade through all this. Damon.
Damon Eckhoff writes:
On 6/13/02 2:07 PM, "Dieter Maurer" <dieter@handshake.de> wrote:
The easiest solution is to use an attribute for your file object, say "file". Then, you can simply use "<url_to_your_instance>/file".
The next easiest solution is a method "viewFile" that uses "getFile" to locate the file object and then calls its "index_html".
Dieter, I appreciate the help...
Okay, I created the viewFile method:
def viewFile( self, REQUEST=None ): "Views the file" self._file.index_html( REQUEST, REQUEST.RESPONSE) You must return the result of calling "index_html"!
return self._file.index_html( REQUEST, REQUEST.RESPONSE) Dieter
participants (2)
-
Damon Eckhoff -
Dieter Maurer