cgi and multipart/form-data?

Discussion in 'Python' started by Chris Curvey, Mar 29, 2005.

  1. Chris Curvey

    Chris Curvey Guest

    I have a form like this:

    <form method="post" enctype="multipart/form-data">
    <input type="file" name="myFile">
    <input type="text" name="foo">
    <input type="submit">
    </form>

    When I submit this form to my Python script using the CGI module, I seem
    to get the "myFile" variable, but I don't seem to the "foo" variable.

    Interestingly, if I take out the "myFile" variable (or specify a much
    smaller file) I do get the value for "foo".

    The files that I'm trying to handle are 400-500Kb in size...is there
    something I need to do (cgi.maxlen?) to let cgi handle big files?
    Chris Curvey, Mar 29, 2005
    #1
    1. Advertising

  2. Chris Curvey

    Chris Curvey Guest

    Chris Curvey wrote:
    > I have a form like this:
    >
    > <form method="post" enctype="multipart/form-data">
    > <input type="file" name="myFile">
    > <input type="text" name="foo">
    > <input type="submit">
    > </form>
    >
    > When I submit this form to my Python script using the CGI module, I seem
    > to get the "myFile" variable, but I don't seem to the "foo" variable.
    >
    > Interestingly, if I take out the "myFile" variable (or specify a much
    > smaller file) I do get the value for "foo".
    >
    > The files that I'm trying to handle are 400-500Kb in size...is there
    > something I need to do (cgi.maxlen?) to let cgi handle big files?


    man, was I on the wrong track. turns out the problem was that I was
    uploading a Excel file and something in there was getting thought of as
    an end-of-file marker. To fix:

    import msvcrt
    msvcrt.setmode(0, os.O_BINARY) # stdin = 0
    msvcrt.setmode(1, os.O_BINARY) # stdout = 1

    (credit where it's due: I found this on ASPN.)
    Chris Curvey, Mar 29, 2005
    #2
    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. Li Zhang
    Replies:
    4
    Views:
    6,062
    softip
    Feb 27, 2009
  2. Matt
    Replies:
    8
    Views:
    142,348
    zeeshanakhter2009
    May 26, 2012
  3. Stefan Fischer
    Replies:
    2
    Views:
    262
    Stefan Fischer
    Feb 23, 2010
  4. Kevin DeValck
    Replies:
    1
    Views:
    723
    7stud --
    May 17, 2011
  5. Replies:
    1
    Views:
    399
Loading...

Share This Page