Wix-media-backend response is 500 when uploading an image as buffer. Buffer created from url. Help needed!

Hi! All of a sudden this code doesn’t seem to work anymore since yesterday and I’m not sure why that’s the case. It’s crucial it’s up and running very soon again as it’s core of the business. It has worked flawlessly for a while, but now my code doesn’t upload images anymore.
See the code below. The commented code was when I was using the Fetch package, but by updating it (thought that it might have something to do with the outdated package) that package didn’t work anymore to create the buffer. So I decided to opt for “buffer-from” NPM package which seems very active. It creates the buffer in the logs, it shows the folder name in the logs, but after that it returns the error from the catch which obviously means something is wrong with the mediaManager . upload . What could this be?

export async function uploadImage ( url , folder , fileName ) {
try {
// const response = await fetch(url);
// console.log('response: ', response);
// const buffer = await response.buffer();
console . log ( 'image url: ’ , url );
const buffer = bufferFrom ( url );

    console . log ( 'buffer:  ' ,  buffer ); 
    console . log ( 'folder:  ' ,  folder ); 
    const  fileInfo  =  await  mediaManager . upload ( folder , 
        buffer , 
        fileName , { 
            "mediaOptions" : { 
                "mimeType" :  "image/jpeg" , 
                "mediaType" :  "image" 
            }, 
            "metadataOptions" : { 
                "isPrivate" :  false , 
                "isVisitorUpload" :  false , 
            } 
        }); 
    return  fileInfo . fileUrl ; 
}  catch  ( error ) { 
    console . log ( "An error occurred while trying to upload an image to Wix. Error:  " ,  error ); 
    throw  new  Error ( 'An error occurred while trying to upload an image to Wix' ); 
} 

}

I have the same issue since January 1st, 2022. Something must have changed on Wix side.

Same issue

Thanks for letting us know. We’ve escalated this issue and will report back as soon as we have an update.

This issue is now resolved. Thanks for your patience!

Thank you! What package would you guys suggest to create the buffer so we can use the MediaManager with said buffer? I do see it’s working, however I get a broken image in the collection now which is most probably an incorrect buffer. Do you have any simple examples regarding this?

@duncanteegelaar
You can instantiate a buffer without adding any additional node packages to your site.
Velo exposes Buffer by default.

For example:

let imageData = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAD0lEQVQYV2NkwAIYaSAIAAGkAAa+Ds1zAAAAAElFTkSuQmCC";

let buffer= Buffer.from(imageData, 'base64');
//Create a buffer from a BASE64 encoded string

The issue here was a bug in mediaManager.upload which has now been resolved by the velo team.

If you are trying to upload a file from a url you should look into
mediaManager.importFile( )
This Imports a file to the Media Manager from a URL.