Question:
I really don’t understand what can cause the issue and why gallery is not updating with new items.
I am getting console error: System error occurred, request-id: 1716075306.126488292727110979" And gallery is not being updated
Product:
Wix EDITOR
What are you trying to achieve:
Updating the gallery with new files(images)
Additional information:
Current frontend code:
if ($w("#uploadPhotos").value.length > 0) {
$w("#infoText").hide();
const uploadedFiles = await $w("#uploadPhotos").uploadFiles();
const inspectionItem = await getInspectionByOrderId(orderId);
await storeInspectionPhotos(inspectionItem._id, uploadedFiles);
const galleryItem = await getGalleryByInspectionId(inspectionItem._id); // Ensure this retrieves the correct gallery item
const galleryDetails = await getGalleryDetails(galleryItem.galleryId);
const newItems = uploadedFiles.map(file => ({
title: file.originalFileName,
description: "",
src: file.fileUrl,
settings: {
focalPoint: [0.5, 0.5]
}
}));
console.log("New items to add:", newItems);
const updatedGallery = await updateGallery(galleryItem.galleryId, newItems, "Updated Gallery");
$w("#gallery1").items = updatedGallery.items.map(item => ({
type: "image",
src: item.image.imageInfo
}));
$w("#infoText").text = "Images uploaded and gallery updated!";
$w("#uploadPhotos").reset();
Backend code:
import wixData from 'wix-data';
import { proGallery } from 'wix-pro-gallery-backend';
import { elevate } from 'wix-auth';
import wixUsers from 'wix-users-backend';
export async function updateGallery(galleryId, items, name) {
try {
if (!galleryId) {
throw new Error("Invalid gallery ID: " + galleryId);
}
console.log("Updating gallery with ID:", galleryId);
console.log("Items:", items);
if (!Array.isArray(items)) {
throw new Error("Items parameter is not an array");
}
const formattedItems = items.map(item => {
if (!item.src) {
throw new Error(`Invalid image source: ${item.src}`);
}
return {
title: item.title || "",
description: item.description || "",
image: {
imageInfo: item.src
},
settings: {
focalPoint: [0.5, 0.5]
}
};
});
const updateOptions = {
name: name,
items: formattedItems
};
const elevatedUpdateGallery = elevate(proGallery.updateGallery);
const updatedGallery = await elevatedUpdateGallery(galleryId, updateOptions);
console.log("Updated gallery:", updatedGallery);
return updatedGallery;
} catch (error) {
console.error("Error updating gallery:", error.message);
throw error;
}
}
Could anyone try to look where is the issue here? I have a felling that i have wrong formatting.
I also checked console how the file src is presented, all looks ok. When creating gallery - i have no issues.
Thanks for help!