Uploading files from a server

drs drs at remove-to-send-mail-ecpsoftware.com
Tue Apr 27 01:17:29 EDT 2004


"Edward Diener" <eldiener at earthlink.net> wrote in message
news:m1gjc.3688$g31.2919 at newsread2.news.atl.earthlink.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





More information about the Python-list mailing list