Droopy : Very simple HTTP file uploads
Summary
Droopy is a mini web server which makes allowing file uploads very easy
I just want to upload this file !
I’ve been writing a system which shares processing tasks across two machines.
Part of this involved shipping an image file from one machine to the other; doing some stuff to the file and then; bringing the file back again.
I was looking around for easy ways to move the files and I found droopy .
To quote the author, Pierre Duqeusne, “Droopy is a mini Web server whose sole purpose is to let others upload files to your computer”. It’s a single python script so as long you’ve got Python installed starting the server is as simple as this
python droopy --message "Upload the bb images here" --picture 0.jpg --dl 8080
And you’re ready to upload files immediately
Image in screendump courtesy of paloetic via flickr
Because of the `–dl` argument used to launch droopy in my example above you also have the option to download files from the same director you’re uploading to.
How I used it
Uploading Files using Requests and Droopy
My solution was written in python so uploading files to the droopy server was very easy using the excellent requests library
def uploadfile(filepath, uploadurl, fileformelementname="upfile"): ''' This will invoke an upload to the webserver on the VM ''' files = {fileformelementname : open(filepath,'rb')} r = requests.post(uploadurl, files=files) return r.status_code uploadStatus = uploadfile(currentFile.fullpath, UPLOADURL, "upfile")
Download Files using urllib and Droopy
I can’t now remember why but I decided to do the download using urllib instead of Requests
def downloadfile(filename, dloadurl, outputdirectory): ''' Pull the converted file off the droopy server ''' fullurl = urljoin(dloadurl, filename) fulloutputpath = os.path.join(outputdirectory, 'divided', filename) urllib.urlretrieve(fullurl, fulloutputpath) downloadfile(currentFile.outputName, DOWNLOADURL, IMGDIR)
Summary
Droopy provides a very useful, very simple web server for both uploading and downloading files. Combined with Python it makes a very useful facility for moving files around under programmtic control.
Versions
All of the above was done on Python 2.7.x.