Saving a base64 image to the media manager with Velo

I’m trying to figure out how to use importFile() or something similar to save a base64 image (loaded in the end user’s browsing session on my site) to Media Manager. I want to save it to media manager and get a link to it.

I’m using the upload() function with this backend code:

export const importFile = webMethod(Permissions.Anyone, (url) => {

  return mediaManager.importFile(

    "/myImportFolder/subfolder",

    url,

    {

      "mediaOptions": {

        "mimeType": "image/jpg",

        "mediaType": "image"

      },

      "metadataOptions": {

        "isPrivate": false,

        "isVisitorUpload": false,

        "context": {

          "someKey1": "someValue1",

          "someKey2": "someValue2"

        }

      }

    }

  );

and this frontend code:



import {Buffer} from "buffer";
import {sendToMediaManager} from "backend/mediaManagerInterface.web";
let b64Img = "data:image/jpeg;base64,/9j/4AAQ........"  // for example
let uploadBuffer = Buffer.from(b64Img, "base64")

sendToMediaManager(uploadBuffer)
  

I keep getting this error:

Error: Error: Unable to handle the request. Contact the site administrator or view site monitoring logs for more information.

“importFile” is for uploading via a url. For a buffer you need to use this API:

Also you may need to generate the buffer itself in the backend.

If you’re still encountering the same error please upload a screenshot of the log from your site events.