RE: How to handle file uploads with http.server

2010-03-17 Thread Neil Blue
Thanks Gabriel

Yep, that looks like the same one. 

Cheers
Neil

 

-Original Message-
From: Gabriel Genellina [mailto:gagsl-...@yahoo.com.ar] 
Sent: 17 March 2010 02:08
To: python-list@python.org
Subject: Re: How to handle file uploads with http.server

En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue 
escribió:

> I have a basic http.server instance running (class 
> HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and 
> I would like to upload files with multipart forms.
>
> def do_POST(self):
>   ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
>   if ctype=='multipart/form-data':
>   print('parsing...')
>   query=cgi.parse_multipart(self.rfile, pdict)
>   print(query)
>
> However the file never seems to finish being parsed. There are no 
> errors, but the call hangs at: query=cgi.parse_multipart(self.rfile, 
> pdict)

This may be related to this bug:

http://bugs.python.org/issue8077

reported last week by Mitchell L. Model in this thread:

http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/

--
Gabriel Genellina



* 

The information contained in this message is likely to be confidential.  It is 
intended only for the person named above.  Any dissemination, distribution, 
copying, disclosure or use of this message or its contents unless authorised by 
BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within 
this e-mail are those of the author and do not necessarily represent those of 
BioWisdom Ltd. If you have received this message in error, please immediately 
notify us and delete it.  Thank you.  Registered Office: BioWisdom Ltd, Harston 
Mill, Harston, Cambridge, CB22 7GG.  Registered in England: (GB) 3861669.  VAT 
registered: (GB) 750899881.  Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, 
Internet:www.biowisdom.com 

*

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to handle file uploads with http.server

2010-03-16 Thread Gabriel Genellina
En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue   
escribió:



I have a basic http.server instance running (class
HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I
would like to upload files with multipart forms.

def do_POST(self):
ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
if ctype=='multipart/form-data':
print('parsing...')
query=cgi.parse_multipart(self.rfile, pdict)
print(query)

However the file never seems to finish being parsed. There are no errors,
but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict)


This may be related to this bug:

http://bugs.python.org/issue8077

reported last week by Mitchell L. Model in this thread:

http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


How to handle file uploads with http.server

2010-03-11 Thread Neil Blue
Hello,

I have a basic http.server instance running (class
HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I
would like to upload files with multipart forms.

def do_POST(self):
ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
if ctype=='multipart/form-data':
print('parsing...')
query=cgi.parse_multipart(self.rfile, pdict)
print(query)

However the file never seems to finish being parsed. There are no errors,
but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict)

Please can anyone offer some insight into this or somewhere else I may find
some more information.

Thanks
Neil

* 

The information contained in this message is likely to be confidential.  It is 
intended only for the person named above.  Any dissemination, distribution, 
copying, disclosure or use of this message or its contents unless authorised by 
BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within 
this e-mail are those of the author and do not necessarily represent those of 
BioWisdom Ltd. If you have received this message in error, please immediately 
notify us and delete it.  Thank you.  Registered Office: BioWisdom Ltd, Harston 
Mill, Harston, Cambridge, CB22 7GG.  Registered in England: (GB) 3861669.  VAT 
registered: (GB) 750899881.  Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, 
Internet:www.biowisdom.com 

*

-- 
http://mail.python.org/mailman/listinfo/python-list


CGI, POST, and file uploads

2010-03-03 Thread Mitchell L Model


On Mar 2, 2010, at 4:48 PM, I wrote:

Can someone tell me how to upload the contents of a (relatively  
small) file using an HTML form and CGI in Python 3.1? As far as I  
can tell from a half-day of experimenting, browsing, and searching  
the Python issue tracker, this is broken.


followed by a detailed example demonstrating the problem.

Having hear no response, let me clarify that this request was  
preliminary to filing a bug report -- I wanted to make sure I wasn't  
missing something here. If nothing else, this failure should be  
documented rather than the 3.1 library documentation continuing to  
describe how to upload file contents with POST. If someone thinks  
there is a way to make this work in 3.1, or that it isn't a bug  
because CGI is hopeless (i.e., non-WSGI-compliant), or that the  
documentation shouldn't be changed, please respond. I'd rather have  
this particular discussion here than in the bug tracking system.


Meanwhile, let me heartily recommend the Bottle Web Framework (http://bottle.paws.de 
) for its simplicity, flexibility, and power. Very cool stuff. To make  
it work in Python3.1, do the following:

1. run 2to3 on bottle.py (the only file there is to download)
	2. copy or move the resulting bottle.py to the site-libs directory in  
your Python installation's library directory
	3. don't use request.GET.getone or request.POST.getone -- instead of  
getone, use get (the protocol changed to that of the Mapping ABC from  
the collections module)
	4. the contents of a file will be returned inside a cgi.FieldStorage  
object, so you need to add '.value' after the call to get in that case


--
http://mail.python.org/mailman/listinfo/python-list


CGI, POST, and file uploads

2010-03-02 Thread Mitchell L Model
Can someone tell me how to upload the contents of a (relatively small)  
file using an HTML form and CGI in Python 3.1? As far as I can tell  
from a half-day of experimenting, browsing, and searching the Python  
issue tracker, this is broken.  Very simple example:



  
  
  
http://localhost:9000/cgi/cgi-test.py";
  enctype="multipart/form-data"
  method="post">
File
   
Submit 

  



cgi-test.py:


#!/usr/local/bin/python3
import cgi
import sys
form = cgi.FieldStorage()
print(form.getfirst('contents'), file=sys.stderr)
print('done')


I run a CGI server with:

#!/usr/bin/env python3
from http.server import HTTPServer, CGIHTTPRequestHandler
HTTPServer(('', 9000), CGIHTTPRequestHandler).serve_forever()



What happens is that the upload never stops. It works in 2.6.

If I cancel the upload from the browser, I get the following output,  
so I know that basically things are working;

the cgi script just never finishes reading the POST input:

localhost - - [02/Mar/2010 16:37:36] "POST /cgi/cgi-test.py HTTP/1.1"  
200 -

<<>>

Exception happened during processing of request from ('127.0.0.1',  
55779)

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/socketserver.py", line 281, in _handle_request_noblock

self.process_request(request, client_address)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/socketserver.py", line 307, in process_request

self.finish_request(request, client_address)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/socketserver.py", line 320, in finish_request

self.RequestHandlerClass(request, client_address, self)
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/socketserver.py", line 614, in __init__

self.handle()
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/http/server.py", line 352, in handle

self.handle_one_request()
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/http/server.py", line 346, in handle_one_request

method()
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/http/server.py", line 868, in do_POST

self.run_cgi()
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/http/server.py", line 1045, in run_cgi

if not self.rfile.read(1):
  File "/Library/Frameworks/Python.framework/Versions/3.1/lib/ 
python3.1/socket.py", line 214, in readinto

return self._sock.recv_into(b)
socket.error: [Errno 54] Connection reset by peer



--
http://mail.python.org/mailman/listinfo/python-list


Re: httplib and large file uploads

2006-10-03 Thread John J. Lee
"Jesse Noller" <[EMAIL PROTECTED]> writes:

> Hey All,
> 
> I'm working on an script that will generate a file of N size (where N is
> 1k-1gig) in small chunks, in memory (and hash the data on the fly) and pass
> it to an httplib object for upload. I don't want to store the file on the
> disk, or completely in memory at any time. The problem arises after getting
> the http connection (PUT) - and then trying to figure out how to
> iterate/hand the chunks I am generating to the httplib connection's send()
> call. For example (this code does not work as is):
[..]

Define "does not work".


John

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: httplib and large file uploads

2006-10-02 Thread Eric S. Johansson
Jesse Noller wrote:
> Hey All,
> 
> I'm working on an script that will generate a file of N size (where N is 
> 1k-1gig) in small chunks, in memory (and hash the data on the fly) and 
> pass it to an httplib object for upload. I don't want to store the file 
> on the disk, or completely in memory at any time. The problem arises 
> after getting the http connection (PUT) - and then trying to figure out 
> how to iterate/hand the chunks I am generating to the httplib 
> connection's send() call. For example (this code does not work as is):

I've been wrestling with a similar one for a while and been mostly held 
up because the Java applet developer has been... less than prompt.

The only way I've been able to successfully upload very large files is 
by performing multiple put requests and on the server-side aggregating 
them into the "real file".  obviously, world will be more difficult if 
you don't have a uniform chunk size or sequential creation of chunks.

---eric

-- 
http://mail.python.org/mailman/listinfo/python-list


httplib and large file uploads

2006-10-02 Thread Jesse Noller
Hey All,I'm working on an script that will generate a file of N size (where N is 1k-1gig) in small chunks, in memory (and hash the data on the fly) and pass it to an httplib object for upload. I don't want to store the file on the disk, or completely in memory at any time. The problem arises after getting the http connection (PUT) - and then trying to figure out how to iterate/hand the chunks I am generating to the httplib connection's send() call. For example (this code does not work as is):
chunksize = 1024size = 10024http = httplib.HTTP(url, '80')http.putrequest("PUT", save_url)http.putheader("Content-Length", str(size))http.endheaders()for i in xrange(size / chunksize):
    chunk = ur.read(chunksize)    http.send(chunk)errcode, errmsg, headers = http.getreply()http.close()In this case, "ur" is a file handle pointing to /dev/urandom. Obviously, the problem lies in the multiple send(chunk) calls. I'm wondering if it is possible to hand 
http.send() an iterator/generator which can pass chunks in as needed.Thanks in advance,-jesse
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: CGI File Uploads and Progress Bars

2005-09-08 Thread Robert Brewer
Doug Helm wrote:
> I'm writing a CGI to handle very large file uploads.
> I would like to include a progress bar.
> ...I need to know not only the number of
> bytes received, but also the total number of
> incoming bytes.  Here's the heart of the code:
> 
> while afcommon.True:
>   lstrData = lobjIncomingFile.file.read(afcommon.OneMeg)
>   if not lstrData:
> break
>   lobjFile.write(lstrData)
>   llngBytes += long(len(lstrData))
> lobjFile.close()
> 
> Assume that lobjIncomingFile is actually a file-type
> element coming from CGI.FieldStorage.  It's already
> been tested to ensure that it is a file-type element.
> Also, assume that I've already opened a file on the
> server, referred to by lobjFile (so lobjFile is the
> target of the incoming data).

I took a cursory look through the cgi module (and am trying to remember
what we did for CherryPy*). It seems that, at the time you run the above
code, the uploaded file has already been completely read from the client
and placed into a temporary file. That is, lobjIncomingFile.file.read
does not read from the HTTP request body; it reads from a temporary file
instead.

> If this were a client application opening a file,
> I would just do the following:
> 
> import os
> print os.stat('myfile.dat')[6]
> 
> But, of course, this isn't a local file.  In fact,
> it's not really a file at all.

In fact, it is a file, just a temporary one. See
cgi.FieldStorage.makefile().

> So, bottom line: Does anyone know how to get the
> size of the incoming file data without reading the
> whole thing into a string?  Can I do something with
> content_header?

Sure. Subclass cgi.FieldStorage, and override make_file to provide your
own file-like object that you can monitor as its "write" method is
called (see read_binary for the actual upload r/w code). The existing
FieldStorage class places the file size (gleaned from the Content-Length
request header) into self.length.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

* See CherryPy's 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI File Uploads and Progress Bars

2005-09-08 Thread Diez B. Roggisch
> So, bottom line: Does anyone know how to get the size of the incoming file
> data without reading the whole thing into a string?  Can I do something with
> content_header?

http://www.faqs.org/rfcs/rfc1867.html

It seems that _maybe_ you can use the content-length http header. But it 
looks as if it's not mandatory in this case - and of course uploading 
multiple files will only allow for an overall percentage.


Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


CGI File Uploads and Progress Bars

2005-09-07 Thread Doug Helm
Hey, Folks:

I'm writing a CGI to handle very large file uploads.  I would like to
include a progress bar.  I think I'm about done.  I have code to handle the
file upload, and I think I can add an IFrame to my page which posts to check
file size (so I can tell how many bytes have been received).  My problem is
that I want to provide a % complete.  In order to do that, of course, I need
to know not only the number of bytes received, but also the total number of
incoming bytes.  Here's the heart of the code:

while afcommon.True:
  lstrData = lobjIncomingFile.file.read(afcommon.OneMeg)
  if not lstrData:
break
  lobjFile.write(lstrData)
  llngBytes += long(len(lstrData))
lobjFile.close()

Assume that lobjIncomingFile is actually a file-type element coming from
CGI.FieldStorage.  It's already been tested to ensure that it is a file-type
element.  Also, assume that I've already opened a file on the server,
referred to by lobjFile (so lobjFile is the target of the incoming data).

If this were a client application opening a file, I would just do the
following:

import os
print os.stat('myfile.dat')[6]

But, of course, this isn't a local file.  In fact, it's not really a file at
all.  It is the contents of a file already rolled up into the HTTP header of
the incoming HTTP request to the Web server.  The CGI module is kind enough
to handle all of the really hard stuff for me (like unpacking and decoding
the header contents, etc.).  But, I still need to know the size of the
incoming file data.

Of course, I could do this by reading the whole thing into a string variable
and then testing the length of the string, as follows:

s = lobjIncomingFile.file.read()
SizeOfFileIs = len(s)

But that really defeats the purpose, since my whole goal here is to provide
a progress bar, which is contingent upon a "chunking" approach.  Besides,
for the file sizes that I'll be dealing with, I surely wouldn't want to read
the whole thing into memory.

So, bottom line: Does anyone know how to get the size of the incoming file
data without reading the whole thing into a string?  Can I do something with
content_header?

Thanks much for any insight that you might have.

Doug


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads

2005-03-31 Thread Doug Helm
You're right, of course, and I do appreciate it.  I generally am calling
functions and returning strings and then printing the entire string.
For example:

def SomeFunc():
  lstrRetVal = ''
  lstrRetVal += 'Content-type: text/html\n\n'
  lstrRetVal += more HTML here...
  return lstrRetVal

Then, the calling code does:

print SomeFunc()

In this case, the extra new line character is appropriate.  Somehow, the
extra new line character slipped in on the print statement in my upload
sample code (I probably copied from a function that returns a string).  But
thanks just the same...

Just to be complete (so that no one comments about string concatenation
efficiency), in a real application I would generally use triple quotes for
HTML (or append to a list and then .join into a string at the end)...

Thanks to all for your help.

"Tim Roberts" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "Doug Helm" <[EMAIL PROTECTED]> 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"
>
> I see you got your problem solved, but you should know there is a problem
> with this line.  The print statement automatically adds an end-of-line, so
> this will actually end up producing TWO blank lines after the header.  You
> should use this:
>
> print "Content-type: text/html\n"
> --
> - Tim Roberts, [EMAIL PROTECTED]
>   Providenza & Boekelheide, Inc.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads

2005-03-30 Thread Tim Roberts
"Doug Helm" <[EMAIL PROTECTED]> 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"

I see you got your problem solved, but you should know there is a problem
with this line.  The print statement automatically adds an end-of-line, so
this will actually end up producing TWO blank lines after the header.  You
should use this:

print "Content-type: text/html\n"
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads

2005-03-28 Thread Doug Helm
Andrew:

I'm a dope.  You're brilliant.  Thank you.  That worked splendidly.

Doug

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Doug Helm wrote:
>
> > form = cgi.FieldStorage()
> >   if lobjUp.Save('filename', 'SomeFile.jpg'):
>
> > class BLOB(staticobject.StaticObject):
> >   def Save(self, pstrFormFieldName, pstrFilePathAndName):
> > form = cgi.FieldStorage()
>
> You are instantiating cgi.FieldStorage twice. This won't work for POST
> requests, because instantiating a FieldStorage reads the form data from
> the standard input stream (the HTTP request).
>
> Try to create a second one and cgi will try to read all the form data
> again; this will hang, waiting for the socket to send it a load more
> data which will not be forthcoming.
>
> When using CGI, parse the input only once, then pass the results (a
> FieldStorage object if you are using the cgi module) in to any other
> functions that need to read it.
>
> --
> Andrew Clover
> mailto:[EMAIL PROTECTED]
> http://www.doxdesk.com/
>


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads -- Windows Server

2005-03-28 Thread "Martin v. Löwis"
Doug Helm wrote:
I'm not getting any error.  I submit a multi-part form to save a file
attachment to disk, and the post just hangs.
You really should look into debugging this. Are you sure your script
is called? To be sure, make the script create a file in c:\tmp.
Is the file being created?
Next, you said you want to know what the command line is. Print sys.argv
to the file. While you are at it, also print os.environ to the file.
Add a print statement after every chunk of code in your CGI script.
Maybe you are getting an exception that is not logged anywhere?
In short, you really have to find out yourself what is going on in your
script. Very few people use IIS (most use Apache instead), so you are
pretty much on your own.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads

2005-03-27 Thread and-google
Doug Helm wrote:

> form = cgi.FieldStorage()
>   if lobjUp.Save('filename', 'SomeFile.jpg'):

> class BLOB(staticobject.StaticObject):
>   def Save(self, pstrFormFieldName, pstrFilePathAndName):
> form = cgi.FieldStorage()

You are instantiating cgi.FieldStorage twice. This won't work for POST
requests, because instantiating a FieldStorage reads the form data from
the standard input stream (the HTTP request).

Try to create a second one and cgi will try to read all the form data
again; this will hang, waiting for the socket to send it a load more
data which will not be forthcoming.

When using CGI, parse the input only once, then pass the results (a
FieldStorage object if you are using the cgi module) in to any other
functions that need to read it.

-- 
Andrew Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


File Uploads -- Windows Server

2005-03-27 Thread Doug Helm
I should have been more clear in my subject line.  I was also the poster in
the "File Uploads" topic.  I'm not having any luck getting file uploads to
work (multi-part HTML form) on a Windows server.  I'm using a very close
approximation of public domain code that I found.  I've tried a couple of
different implementations (very similar), but I am essentially using the
following test code:

http://www.voidspace.org.uk/python/cgi.shtml#upload

which does *not* work on my Windows / IIS server.  I have CGIs (py and pyc
files) configured as follows:

C:\Python\Python.Exe -u %s %s

C:\Python is (of course) where Python is installed on my machine.
-u allows for binary data to be processed (I believe)
I'm not sure what %s %s does (would be nice to know...)

Anyway, I believe I have write permissions in the directory that I'm trying
to write (and would expect an error if I didn't)...

I'm not getting any error.  I submit a multi-part form to save a file
attachment to disk, and the post just hangs.

Does anyone have any ideas on this?  Has anyone made CGI file uploads work
in a Windows / IIS environment?

Thanks much for any help that you can provide.

Doug


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads

2005-03-27 Thread dimitri pater
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 <[EMAIL PROTECTED]> 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" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > 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 <[EMAIL PROTECTED]>
> 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 """
> > > 
> > > 
> > > 
> > >  > > enctype="multipart/form-data">
> > > 
> > > 
> > > 
> > > 
> > > 
> > > """
> > > else:
> > >   import BLOB
> > >   lobjUp = BLOB.BLOB()
> > >   if lobjUp.Save('filename', 'SomeFile.jpg'):
> > > print """
> > > 
> > > 
> > > 
> > >   File successfully saved.
> > > 
> > > 
> > > """
> > >   else:
> > > print """
> > > 
> > > 
> > > 
> > >   Unable to save file.
> > > 
> > > 
> > > """
> > >
> > > --
> > >
> > > 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Uploads

2005-03-27 Thread Doug Helm
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" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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 <[EMAIL PROTECTED]>
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 """
> > 
> > 
> > 
> >  > enctype="multipart/form-data">
> > 
> > 
> > 
> > 
> > 
> > """
> > else:
> >   import BLOB
> >   lobjUp = BLOB.BLOB()
> >   if lobjUp.Save('filename', 'SomeFile.jpg'):
> > print """
> > 
> > 
> > 
> >   File successfully saved.
> > 
> > 
> > """
> >   else:
> > print """
> > 
> > 
> > 
> >   Unable to save file.
> > 
> > 
> > """
> >
> > --
> >
> > 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


Re: File Uploads

2005-03-27 Thread dimitri pater
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 <[EMAIL PROTECTED]> 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 """
> 
> 
> 
>  enctype="multipart/form-data">
> 
> 
> 
> 
> 
> """
> else:
>   import BLOB
>   lobjUp = BLOB.BLOB()
>   if lobjUp.Save('filename', 'SomeFile.jpg'):
> print """
> 
> 
> 
>   File successfully saved.
> 
> 
> """
>   else:
> print """
> 
> 
> 
>   Unable to save file.
> 
> 
> """
> 
> --
> 
> 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


File Uploads

2005-03-27 Thread Doug Helm
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 """









"""
else:
  import BLOB
  lobjUp = BLOB.BLOB()
  if lobjUp.Save('filename', 'SomeFile.jpg'):
print """



  File successfully saved.


"""
  else:
print """



  Unable to save file.


"""

--

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