Hello everyone,
I get data transferred to my Wix page via an html1_message from an integrated iFrame. This data contains an image as base64, which I want to upload to the Media Manager. Some time ago my code still worked, but now I get different error messages depending on the image. If I use a more complex image (image contains images, etc.), I get error 413. According to the documentation, the MediaManager allows 25 MB. However, the image only has 5 MB. If I try to upload a simpler image, I get the 504 error.
I have attached my method call and the method behind it. However, it seems that the method is no longer being called correctly. None of my console.log attempts within the function were output.
Page Code:
import { uploadImage } from 'backend/mediaManagerHandler'
export function html1_message(event) {
let receivedData = event.data;
uploadImage(receivedData.draft, receivedData.draftname)
.then((result) => {
// do something
})
.catch((err) => {
console.log("err);
});
// Add draft to cart
cart.addProducts([{
// Product stuff
}])
// Update cart with new draft
.then((updatedCart) => {
// Products added to cart
const cartId = updatedCart._id;
const cartLineItems = updatedCart.lineItems;
if (formFactor !== "Mobile") {
cart.showMiniCart();
}
})
.catch((error) => {
console.error(error);
});
}
mediaManagerHandler:
export async function uploadImage(buffer, name="unknown") {
var image = buffer.replace("data:image/jpeg;base64,", "")
var imageToUpload = Buffer.from(image, 'base64')
const mediaOpt = {
"mediaOptions": {
"mimeType": "image/jpeg",
"mediaType": "image"
},
"metadataOptions": {
"isPrivate": false,
"isVisitorUpload": false
}
}
const fileName =`${name}.jpeg`;
const folderPath = "/path/to/folder";
try {
return await mediaManager.upload(folderPath, imageToUpload, fileName, mediaOpt);
} catch (err) {
console.error('Failed to upload image:', err);
throw err;
}
}