user1177284
user1177284

Reputation: 65

Python Bottle upload file without form

I'm trying to save files sent from C++ code(not by HTML)
But I do not know how to write the script to parse sent data and save it
C++ code works fine(from wireshark captured packet)

from Bottle tutorial: how do I edit it?
category = request.forms.get('category')
upload = request.files.get('upload')
thanks!

update:
I found that request.files works

files = request.files
for name, fobj in files.iteritems():
    fobj.save(some_path)

Upvotes: 2

Views: 552

Answers (2)

kapkark
kapkark

Reputation: 1

This is what I ended up doing:

from bottle import FileUpload

uploaded_file = FileUpload(request.body, None, filename='some_filename')
uploaded_file.save() # implement conflict resolution here, if needed

Upvotes: 0

CasualDemon
CasualDemon

Reputation: 6168

If you are just sending the raw file in the HTTP request, access it with request.body.

http://bottlepy.org/docs/dev/api.html#bottle.BaseRequest.body

Upvotes: 1

Related Questions