I want to download image from Python CGI.
For example, I post img's base64 to CGI, and CGI output image.
I write this code.
Please advise me.
Python cgi side code
import cgi
import base64
query = cgi.FieldStorage()
img_list = query.getvalue("image").split(',')
contentType = img_list[0] #data:image/jpeg;base64
base_64 = img_list[1]
print("Content-type: image/jpeg")
print(base64.b64decode(base_64))
Have a try:
print("Content-Type: application/octet-stream")
This means that it is raw bytes and can not be interpreted as anything useful by the browser. The browser should then open a download dialog.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.