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' );
}
}