Search code examples
pythonbase64storagegcloud

How to upload base64 image to GCloud Storage


How do you upload an image from your web to gcloud Storage?

  • client: React app
  • server: Python(Flask)

CLIENT SIDE: I have a file browse component where I choose an image from the local drive. Then, I transform the image into a base64 string, and send it to the server.

SERVER-SIDE: Then I upload the base64 image: blob.upload_from_string(base64data, type="image/jpeg")

But when I look inside my bucket I see a 1 black pixel image.

Questions

  • Can I upload a base64 image right into my bucket?
  • Why does my image is being procced as a black pixel? where does it break?

Solution

  • In the end what i did was to remove the first part of the string data:image/jpeg;base64,, (of course its not necessarily a jpeg.. its just an example). I decoded the rest of the string back to an image, and passed the content_type also.

    That solved my problem