Uploading files from a server

E

Edward Diener

What is the easiest way in Python in a web server to upload a client file,
once the file name on the client's machine has been entered, to a directory
on the server ?
 
P

Peter Hansen

Edward said:
What is the easiest way in Python in a web server
^^^^^^^^^^^^^^^^^^^^^^^^^
What does this mean? Are you asking about a specific situation
you have already, such as Python CGI scripts running behind
an Apache server, or are you asking for suggestions for a web
framework which can handle this task, where the web server
itself is written in Python? Or something else?
to upload a client file,
once the file name on the client's machine has been entered, to a directory
on the server ?

That is done using the usual means laid out by the HTTP and HTML
standards, same with Python as with any other language. Are
you actually asking how this is done? (That is, using POST,
and an input type of "file", and so forth...)

Please clarify what you really want.

-Peter
 
D

drs

Edward Diener said:
What is the easiest way in Python in a web server to upload a client file,
once the file name on the client's machine has been entered, to a directory
on the server ?

I think this is what you want ... this is for mod_python with the publisher
handler. It will allow a user to upload a file and save it on a server. It
provides no protection or checking, however. other server configurations
will be slightly different.

first, use a form tag and input tag like

<form method=POST action="./upload_function/" ENCTYPE="multipart/form-data">
<input type="file" id="uploaded_file" name="uploaded_file">
<input type="submit">
</form>

The above will get the file to your server. then use an upload function
like:

def upload_function(req, uploaded_file=None):
if uploaded_file:
fn1 = str(uploaded_file.filename).split('\\')[-1]
fn = fn1.split('/')[-1]
# the weird file splitting is because os.path on Freebsd, where this
ran,
# didn't deal with win32 and unix file paths for uploaded files
d = uploaded_file.read()
f = open('/save/path/%s' % fn, 'w')
f.write(d)
f.close()
return 'uploaded'
else: return 'no file'

-d
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top