python - Convert Base 64 String to BytesIO -


thanks can this, first question it's not super obvious.

i have image that's being passed base64 string (using slim image cropper). want convert file send google storage blob.

previously i've been sending file below

image = request.files.get('image') client = _get_storage_client() bucket = client.bucket(current_app.config['cloud_storage_bucket']) blob = bucket.blob(filename)  blob.upload_from_string(     image.read(),     content_type=content_type) 

now i'm dealing below code.

cropped_image = json.loads(request.form.get('slim[]')) data = cropped_image['output']['image'] 

data variable string:

data = 'data:image/jpeg;base64,/9j/4aaqskzjrgabaqaaaqabaad/2wbd...' 

i'm stuck not sure if need encode base64, decode base64, turn bytestring encode/decode??

i've tried sending using bytesio , stringio

image = bytesio(data) blob.upload_from_string(     image.read(),     content_type=content_type) 

and black picture uploaded, try not ask questions without researching first 1 has me stumped.

thanks.

re.sub("data:image/jpeg;base64,", '', b64_str).decode("base64") works in python2. in py 2, str bytes actually.

update

from base64 import b64decode  open("test.jpeg", 'wb') f:     f.write(b64decode(re.sub("data:image/jpeg;base64,", '', b64_str)))  # or  image = bytesio(b64decode(re.sub("data:image/jpeg;base64", '', b64_str))) 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -