There’s not much to say beyond the documentation examples, but I was looking for a way to do streaming uploads from Python, and poster delivers nicely on the client side.
Writing a server side streaming downloader in mod_python is infinitely easier and looks something like this:
def handle_upload(self):
self.form_data = util.FieldStorage(self.request)
for key in self.form_data.keys():
value = self.form_data[key]
if type(value) == types.InstanceType:
if isinstance(value, util.StringField):
pass
elif isinstance(value, util.Field):
filename = value.filename
content_type = value.type
base = os.path.basename(value.filename).strip()
fd = open("/tmp/apache/%s\n" % base, "wb")
while True:
data = value.file.read(1024)
fd.write(data)
if data == "":
fd.close()
break
return apache.OK
Security and error handling (as well as writing the rest of the mod_python handler, however minimal that might be) are left as an exercise to the reader.
Advertisement