File Uploads

dimitri pater dimitri.pater at gmail.com
Sun Mar 27 18:30:48 EST 2005


No, I am on a Linux server. I am not sure how CGI is configured
because I do not control the server, I only use it.

bye,
Dimitri


On Sun, 27 Mar 2005 16:19:00 -0700, Doug Helm <dhelm at wcsoftware.com> wrote:
> Thanks, Dimitri.  Yes, I found that same code too and tried it with the
> exact same result as the code I've uploaded (just hangs).  But, OK.  You
> have it working, so it must be a systems issue.  Are you also on a Windows
> IIS web server?  Do you have CGI configured the same way (i.e. .py =
> python.exe -u %s %s)?
> 
> Thanks.
> 
> Doug
> 
> "dimitri pater" <dimitri.pater at gmail.com> wrote in message
> news:mailman.924.1111960549.1799.python-list at python.org...
> > Maybe this helps:
> > http://www.voidspace.org.uk/python/cgi.shtml#upload
> >
> > I use it, it works for fine me
> > Maybe it will give you some clues on how to tweak your own script.
> >
> > Dimitri
> >
> >
> > On Sun, 27 Mar 2005 10:32:20 -0700, Doug Helm <dhelm at wcsoftware.com>
> wrote:
> > > Hey, Folks:
> > >
> > > I'm trying to write a very simple file upload CGI.  I'm on a Windows
> server.
> > > I *am* using the -u switch to start Python for CGIs, as follows:
> > >
> > > c:\python\python.exe -u %s %s
> > >
> > > I *do* have write permissions on the directory I'm trying to write to.
> But,
> > > when I click submit, it just hangs.  Any help would be greatly
> appreciated.
> > > Thanks.  Here's the code...
> > >
> > > Upload.py
> > >
> > > import cgi
> > >
> > > print "content-type: text/html\n\n"
> > >
> > > form = cgi.FieldStorage()
> > > if not form:
> > >   print """
> > > <html>
> > > <head></head>
> > > <body>
> > > <form name="frmMain" action="Upload.py" method="POST"
> > > enctype="multipart/form-data">
> > > <input type="file" name="filename"><br>
> > > <input type="submit">
> > > </form>
> > > </body>
> > > </html>
> > > """
> > > else:
> > >   import BLOB
> > >   lobjUp = BLOB.BLOB()
> > >   if lobjUp.Save('filename', 'SomeFile.jpg'):
> > >     print """
> > > <html>
> > > <head></head>
> > > <body>
> > >   File successfully saved.
> > > </body>
> > > </html>
> > > """
> > >   else:
> > >     print """
> > > <html>
> > > <head></head>
> > > <body>
> > >   Unable to save file.
> > > </body>
> > > </html>
> > > """
> > >
> > > --------------
> > >
> > > Blob.py
> > >
> > > import cgi
> > > import staticobject
> > >
> > > cTrue = 1
> > > cFalse = 0
> > >
> > > try:
> > >   import msvcrt,os
> > >   msvcrt.setmode( 0, os.O_BINARY ) # stdin  = 0
> > >   msvcrt.setmode( 1, os.O_BINARY ) # stdout = 1
> > > except ImportError:
> > >   pass
> > >
> > > class BLOB(staticobject.StaticObject):
> > >
> > >   def __init__(self):
> > >     self.initializing = cTrue
> > >     staticobject.StaticObject.__init__(self)
> > >     self.initializing = cFalse
> > >
> > >   def Save(self, pstrFormFieldName, pstrFilePathAndName):
> > >
> > > # tried this first -- same result -- just hangs...
> > > #    try:
> > > #      form = cgi.FieldStorage()
> > > #      item = form[pstrFormFieldName]
> > > #      if item.file:
> > > #        data = item.file.read()
> > > #        f = open(pstrFilePathAndName,'wb')
> > > #        f.write(data)
> > > #        f.close()
> > > #        return cTrue
> > > #      else:
> > > #        return cFalse
> > > #    except:
> > > #      return cFalse
> > >
> > >     form = cgi.FieldStorage()
> > >     f = open(pstrFilePathAndName,'wb')
> > >     f.write(form[pstrFormFieldName].value)
> > >     f.close()
> > >
> > > --
> > > http://mail.python.org/mailman/listinfo/python-list
> > >
> >
> >
> > --
> > Please visit dimitri's website: www.serpia.com
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Please visit dimitri's website: www.serpia.com



More information about the Python-list mailing list