Uploading files from a server

Discussion in 'Python' started by Edward Diener, Apr 26, 2004.

  1. 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 ?
    Edward Diener, Apr 26, 2004
    #1
    1. Advertising

  2. Edward Diener

    Peter Hansen Guest

    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
    Peter Hansen, Apr 27, 2004
    #2
    1. Advertising

  3. Edward Diener

    drs Guest

    "Edward Diener" <> wrote in message
    news:m1gjc.3688$...
    > 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
    drs, Apr 27, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. raymond chiu

    Uploading files to Windows Server

    raymond chiu, Jan 6, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    498
    =?Utf-8?B?Tm90SGVscGZ1bA==?=
    Jan 12, 2006
  2. Rosie Chua

    Uploading files up to 150MB onto server

    Rosie Chua, Jun 26, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    3,376
    Russ Bishop
    Jun 26, 2003
  3. Dung Ping
    Replies:
    10
    Views:
    941
    Chaddy2222
    Jan 16, 2006
  4. dermoon
    Replies:
    0
    Views:
    456
    dermoon
    Oct 8, 2003
  5. Andrew Chan

    Problems: uploading files have Chinese named files

    Andrew Chan, Apr 16, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    163
    Andrew Chan
    Apr 16, 2004
Loading...

Share This Page