473,388 Members | 1,230 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

how do i do this - stream file

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
3 2063
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stu | last post by:
Hi, Im reading a file in from disk as a byte array then passing it to a memory stream for decryption using crypto api functions. What I have found is that you need to reduce the array length by 2...
10
by: Russell Mangel | last post by:
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore>...
0
by: gary_dr | last post by:
What's so special about istream_iterator that prevents me from determining the distance between two of them. In the code below, search() does return a foundAt iterator that points to the location...
4
by: Scott, Killer of all Ninjas | last post by:
It seems incredulous to me that it is so difficult to write the contents of a memory stream to a file. I'm certain that I'm missing something simple. I am retrieving a memory stream from a DIME...
3
by: terrorix | last post by:
Hi, I have function which return instance of object Stream and i want that stream object to save to file. How can i do that? my code is: Stream s = MyGetStream(); my question is what i...
0
by: JackRazz | last post by:
I'm trying to serialize a collection to a file stream by serializing each object individually. The code below works fine with the BinaryFormatter, but the SoapFormatter reads the first object and...
3
by: frustrated | last post by:
I am trying to share a file stream between two threads, but havent got a clue as to how to do it. The first thread will be reading the file, and the second thread will(/might) be writing to the...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
19
by: deepak | last post by:
How the following code is working. main() { int a = 38, b = 13; unsigned long long c; c = a * (1<<b) * 32000; printf("%llu", c);
5
by: Chad | last post by:
say my input file is $ more suck ______ < gnu? > ------ \ , , \ /( )` \ \ \___ / | /- _ `-/ '
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.