Simple python cgi question

S

Stephen Boulet

First of all, I'm not sure that the easiest way to do this is with
python ...

I'd like to set up a web page that would accept a text file, process it
with a local program, and then make available generated pdf and
postscript files for downloading.

I'd like to limit the size of the file to be uploaded.

I have apache2 already up. Is this a job for (mod_)python?

-- Stephen
 
W

Wilk

Stephen Boulet said:
First of all, I'm not sure that the easiest way to do this is with
python ...

I'd like to set up a web page that would accept a text file, process
it with a local program, and then make available generated pdf and
postscript files for downloading.

I'd like to limit the size of the file to be uploaded.

I have apache2 already up. Is this a job for (mod_)python?

Yes why not ?
 
D

Domenico

First of all, I'm not sure that the easiest way to do this is with
python ...

python works great as a glue language. and you can *definitely* write
that script in python.
I'd like to set up a web page that would accept a text file, process it
with a local program, and then make available generated pdf and
postscript files for downloading.

no problem at all -- use os.system() or open a pipe via popen. then
serve a page with links to the generated files. finally (if you're a
1337 sysadmin) set up a cron job which every hour deletes .pdf and .ps
files older than (let's say) 5 minutes.
I'd like to limit the size of the file to be uploaded.

read the file into a buffer and stop reading after reaching the size
you decide. (disclaimer: I've never done this myself ;)

domenico
 
S

Stephen Boulet

I don't want report lab since I'll be using lilypond to generate the
pdfs (I mentioned that I'd be calling the pdf generating program from
python).

What I needed to know was how to upload a file, really. I thought it
might be trivial, but maybe not so ...

I'll have to give the mod_python docs some study.

-- Stephen
 
L

Lothar Scholz

Stephen Boulet said:
First of all, I'm not sure that the easiest way to do this is with
python ...

I'd like to set up a web page that would accept a text file, process it
with a local program, and then make available generated pdf and
postscript files for downloading.

I'd like to limit the size of the file to be uploaded.

I have apache2 already up. Is this a job for (mod_)python?

-- Stephen

File upload size restriction is a job for apache. If you try to do
this in a CGI handler its to late to protect against "Denial Of
Service" attacks.

With modpython you can check the content-length header and abort
before you process the data.
 
W

Wilk

Stephen Boulet said:
I don't want report lab since I'll be using lilypond to generate the
pdfs (I mentioned that I'd be calling the pdf generating program from
python).

What I needed to know was how to upload a file, really. I thought it
might be trivial, but maybe not so ...

Yes it's trivial, you'll retreive the file with cgi.FieldStorage(),
you'll pass it to your local app with popen (a pipe) and retreive the
pdf with the pipe or open (a file), control the size of the buffer and
send the result with print.

Before, you'll print the right header content-type: application/pdf

bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top