"This resource is not a valid image" when trying to store an image from a base64 string.

Options

Hi Xano-ers, I'm having trouble trying to store an image from a 3rd party API that comes through as a base64 string, and I'm not quite sure what I'm doing wrong.

Here's what I'm currently doing—

I first use the "Create file resource" function with file name as "newFile.png" and file data as a variable of the base64 string for the image

This step returns a funky string that looks like this.

After this step, I use the "Create image from file" function using the returned value from the screenshot above. This is where I run into problems—I keep getting a "This resource is not a valid image." message from Xano.

Any idea what might be the problem?

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options

    Hey Wes, I suspect the value is still base64 encoded at that point. First pass idea: create a new variable (image decodes?) with the value of the image with the filter base64_decode run on it before you make the file resource.

  • Wes Wagner
    Options

    @Ray Deck Great suggestion—that worked! Thank you.

    For whoever else runs into this in the future(or for improving the Xano docs CC @Michael Udinski): the docs mention that the file resource input can handle a base64 encoded file, but there isn't clarity on what the "create a file resource" function can handle. From this, it seems it does not handle base64 encoded files—you have to decode them first like Ray suggested.

  • Chris Coleman
    Chris Coleman Administrator

    ADMIN

    Options

    Hey Wes, thanks for the heads up on this! We've made sure to update our documentation to reflect this difference and will look at improving this in the future.