I'm trying to upload a binary file to a Flask endpoint without using any type of multipart/form-data
. I'd like to simply POST
or PUT
the data inside the file to the endpoint, and save it to a file on the server. The only examples I can find, and the only method discussed in other questions, uses multipart/form-data
.
The following "works", but the SHA256 hashes usually don't match, whereas uploading as form-data
works fine.
@application.route("/rupload/<filename>", methods=['POST', 'PUT'])
def rupload(filename):
# Sanity checks and setup skipped.
filename = secure_filename(filename)
fileFullPath = os.path.join(UPLOAD_FOLDER, filename)
with open(fileFullPath, 'wb') as f:
f.write(request.get_data())
return jsonify({
'filename': filename,
'size': os.path.getsize(fileFullPath)
})
Additionally, the above is very inefficient with memory. Is there a way to write it to the output file via some type of buffered stream? Thanks!
Edit: This is how I'm testing this:
curl -v -H 'Content-Type: application/octet-stream' -X POST --data @test.zip https://example.com/test/rupload/test.zip
Edit: --data-binary
makes no difference.