By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,886 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,886 IT Pros & Developers. It's quick & easy.

how do i do this - stream file

P: n/a
hi!

How do i create and stream a file?
On a webpage i have a link to a file. Next to it i would like link, which,
when pressed, runs a script that calculates the signature of the file,
pickles the signature to a file and then gives a dialog box asking the
user whether they would like to save the file or open it.

I have the script to do the signing and pickle the signature into a file,
but how do i allow the user to download it?

thanks

cheers

--
Ajay Brar,


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> How do i create and stream a file?
On a webpage i have a link to a file. Next to it i would like link, which,
when pressed, runs a script that calculates the signature of the file,
pickles the signature to a file and then gives a dialog box asking the
user whether they would like to save the file or open it.

I have the script to do the signing and pickle the signature into a file,
but how do i allow the user to download it?


You'll need a webserver - there exist simple http-servers in the standard
modules, you can use twisted or one of the plethorea of
web-serving-solutions that exist for python, like (on particular order nor
a complete list) quixote, zope, mod_python and so on....

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

P: n/a
On Tue, 3 Aug 2004, Ajay wrote:
I have the script to do the signing and pickle the signature into a file,
but how do i allow the user to download it?


Instead of pickling it to a file, pickle it to a string (using dumps).
Then you can change your script to a CGI script like the following:

#!/usr/local/bin/python <-- replace this with the real location of Python
on your server
import sys
from pickle import dumps

<do stuff>

mydata = dumps(<something>)

sys.stdout.write('Content-type: application/x-pickle\n\n')
sys.stdout.write(mydata)

That first sys.stdout.write is all that's needed to make a basic CGI
script: the Content-type line tells the web browser what type of
information to expect (the MIME type). Then you can just send whatever
data you like (this works with print statements too; but remember that
they append a \n to your data).

For normal web pages, the MIME type is text/html. The type
application/x-pickle is just something I made up, since there is no MIME
type corresponding to pickled data. You may even consider just sending
the signature as text and use the standard MIME type text/plain.

You should put your script in the cgi-bin/ directory on your web
server, and set its executable bit if it's a Unix server.

Jul 18 '05 #3

P: n/a
Actually this can happen automatically. If the
user's machine doesn't have a file association for
the file extension of the file that they click on
the browser automatically displays a open/save
dialog for them when they click on the hyperlink.
If they have an association defined on their machine,
for the extension it launches the application when
they click the hyperlink. On Windows this behavior
is configurable. They can always right click on
hyperlink and choose save instead.

HTH,
Larry Bates
Syscon, Inc.

"Ajay" <ab******@mail.usyd.edu.au> wrote in message
news:ma**************************************@pyth on.org...
hi!

How do i create and stream a file?
On a webpage i have a link to a file. Next to it i would like link, which,
when pressed, runs a script that calculates the signature of the file,
pickles the signature to a file and then gives a dialog box asking the
user whether they would like to save the file or open it.

I have the script to do the signing and pickle the signature into a file,
but how do i allow the user to download it?

thanks

cheers

--
Ajay Brar,


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.