Hi list, I write a python script which return a selected file to download. The script receive value from a form to choose the kind of file to download (and increment the counter of the file selected): For example, in a folder i have 2 files ("A.tgz" and "B.tgz") and a Page Template Object (chooseFileToDownload.html). This page is a form with multiple choice in order to seclect a file to download (if the user select "A" button, he must get the A.tgz file, if select "B" he must get A.tgz ...) I write the python script method to select the file but i don't know how the script sends the file to download: With the variable "fileToDownload" which contain the name of the file selected, if i write "return fileToDownload" in my script i get all the file (in his compressed format) in my navigator windows, but *no* a popup windows which ask me where i want to save the file like we have any time we want to download a file. Thanks for any help ! _______________________________________________ Hervé RICHARD Herve.Richard@avignon.inra.fr INRA - Biometrie _______________________________________________
Hervé Richard wrote:
I write a python script which return a selected file to download. The script receive value from a form to choose the kind of file to download (and increment the counter of the file selected): For example, in a folder i have 2 files ("A.tgz" and "B.tgz") and a Page Template Object (chooseFileToDownload.html). This page is a form with multiple choice in order to seclect a file to download (if the user select "A" button, he must get the A.tgz file, if select "B" he must get A.tgz ...)
I write the python script method to select the file but i don't know how the script sends the file to download: With the variable "fileToDownload" which contain the name of the file selected, if i write "return fileToDownload" in my script i get all the file (in his compressed format) in my navigator windows, but *no* a popup windows which ask me where i want to save the file like we have any time we want to download a file.
There are many a way to get an object based on a string. See zopelabs.com for some examples. One of the most common is:: name = "some_string" obj = context[name] What you want to do with 'obj' depends on what you really want. If you intend to write the contents of the object, you can:: return obj.index_html() # or return obj.data You can redirect to that object like:: context.REQUEST.RESPONSE.redirect(obj.absolute_url()) The file download dialogue is a function of the browser, and it will always do this for MIME types it recognizes as non-displayable. I think the first method may fool it sufficiently that it displays the (mostly nonsense) contents of an archive file in the browser. --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
On Thu, 15 Jan 2004 12:09:14 -0600 "J. Cameron Cooper" <jccooper@jcameroncooper.com> wrote:
Hervé Richard wrote:
I write a python script which return a selected file to download. The script receive value from a form to choose the kind of file to download (and increment the counter of the file selected): For example, in a folder i have 2 files ("A.tgz" and "B.tgz") and a Page Template Object (chooseFileToDownload.html). This page is a form with multiple choice in order to seclect a file to download (if the user select "A" button, he must get the A.tgz file, if select "B" he must get A.tgz ...)
I write the python script method to select the file but i don't know
how the script sends the file to download: With the variable "fileToDownload" which contain the name of the file selected, if i write "return fileToDownload" in my script i get all the file (in his compressed format) in my navigator windows, but *no* a popup windows which ask me where i want to save the file like we have any time we want to download a file.
There are many a way to get an object based on a string. See zopelabs.com for some examples. One of the most common is::
name = "some_string" obj = context[name]
What you want to do with 'obj' depends on what you really want. If you
intend to write the contents of the object, you can::
return obj.index_html() # or return obj.data
The above will only work if the file is less than the file chunk size (64K). Otherwise the former will not actually return anything (instead it will write directly to the RESPONSE), and the latter will only return the first 64K of the data. The canonical way to get the data from a file object is (drum roll please...): str(obj) This will work regardless of the size of the object. Granted it will create an in-memory string that is the same size as the file data. So be careful doing this if the file data is large. -Casey
participants (3)
-
Casey Duncan -
Hervé Richard -
J. Cameron Cooper