Bottle file upload and process

 with open(filename,'w') as open_file:
    open_file.write(data.file.read())

dont work

you can use

data = request.files.data
data.save(Path,overwrite=True)

The file will be handled by the routine you use. That means your read handles the connection (the file should not be there, according to wsgi spec)


Ok, let's break this down.

The full code is:

HTML:

<form action="/upload" method="post" enctype="multipart/form-data">
  <input type="text" name="name" />
  <input type="file" name="data" />
</form>

PYTHON CODE:

from bottle import route, request
@route('/upload', method='POST')
def do_upload():
    name = request.forms.name
    data = request.files.data
    if name and data and data.file:
        raw = data.file.read() # This is dangerous for big files
        filename = data.filename
        return "Hello %s! You uploaded %s (%d bytes)." % (name, filename, len(raw))
    return "You missed a field."

(From the doc's you provided)

So, first of all, we can see that we first pull the information from the name and the data in the html form, and assign them to the variables name and data. Thats pretty straight forward. However, next we assign the variable raw to data.file.read(). This is basically taking all of the file uploaded into the variable raw. This being said, the entire file is in memory, which is why they put "This is dangerous for big files" as a comment next to the line.

This being said, if you wanted to save the file out to disk, you could do so (but be careful) using something like:

with open(filename,'w') as open_file:
    open_file.write(data.file.read())

As for your other questions:

1."What would be the best way to start the system command with the file as an argument? Is it possible to just pass the path to an existing file directly?"

You should see the subprocess module, specifically Popen: http://docs.python.org/2/library/subprocess.html#popen-constructor

2."Will the uploaded file be directly available to other tools without .read() and then manually saving the bytes to a specified file on disk?"

Yes, you can pass the file data around without saving it to disk, however, be warned that memory consumption is something to watch. However, if these "tools" are not in python, you may be dealing with pipes or subprocesses to pass the data to these "tools".