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

Uploading files from a server

P: n/a
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 ?
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Edward Diener wrote:
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
Jul 18 '05 #2

P: n/a
drs
"Edward Diener" <el******@earthlink.net> wrote in message
news:m1*****************@newsread2.news.atl.earthl ink.net...
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
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.