How to read request.files ['image'] as base64?

I am using Python Flask as my backend and have run into a small problem. In an external application, I have a form containing an image upload function.

In the backend, I relate the variable to the image with image = request.files['image']

This exports the object FileStorage.

I want to convert the image to base64 format to insert it into my db. I tried a lot, but nothing worked. Somebody knows?

+4
source share
1 answer

Basically you need to read it as a stream, and then convert it to base64 format. Check the following answer:

Base64 encoded image file

shoud :

import base64

...

image = request.files['image']  
image_string = base64.b64encode(image.read())
+7

Source: https://habr.com/ru/post/1677793/


All Articles