I want to pass a uploaded file from multipart/form-data directly to my DLL function, without saving it as a temporary file.
My c-style DLL function looks like:
int process_image(unsigned char* image, int size);
The argument "image" is expected to be a binary array containing the complete data of a jpeg file, and the argument "size" is the size of "image". Since this data is exactly a part of the multipart/form-data, I want to extract it and pass it directly to the DLL function using Flask and ctypes.
But after I looked into Flask, I found Flask extracts the files from multipart/form-data as FileStorage objects (request.files) like:
@app.route("/", methods=['POST'])
def getimages():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
So my questions are:
- How can I get the binary image (jpeg) data from multipart/form-data using Flask?
- Then how can I convert this binary data using ctypes and pass it directly to my DLL function?