How do I go from Image from Database to Base64 string?

Options

I currently have it so that when I receive an image from it is stored in a database as the image, I want to send this image to Google Vision API. To do that I need to send it as a Base64 string, but I can't figure out how to convert this image to a Base64 so that it can be understood by the Google Vision API. Any help?

Tagged:

Answers

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hey, @Phil. Should be pretty simple!

    1. Query the database to get the URL of the file.
    2. Create File Resource, providing the URL of the file as the file data.
    3. Get File Resource Data on the output from step 2
    4. Create Variable with the value being the .data path in the variable that step 3 outputs, and a base64_encode filter.

    This will retrieve the raw file data so the function stack can manipulate it, and encode that raw file data into base64 format to send to Google.

    You may need to use base64_encode_urlsafe instead depending on how Google expects the data to be sent.

    Let me know if you have any questions!

  • Phil
    Phil Member
    Options

    Hey, thanks for the explanation I probably just messed something up when trying to put it into action. This is what I just tried and it didn't seem to work, obviously I dont have the API setup in this yet I'm just trying to see if I can get it to code it in Base64 before I add the API in. Thoughts? Thanks again

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hey, Phil! Almost there. After the "create file resource" step, you'll want to insert a Get File Resource Data step, targeting your Data variable. Then in your Create Variable, you'd target the output of that new step, specifically the .data path, and apply the base64_encode filter.

  • Lefteris - blupry.com
    Options

    Hey @Phil

    It could be easier if you convert the image to base64 on the front end.

    We have build two templates that are doing that, one is for flutterflow and one for Thunkable