From 8ad813e4f40bdd4611d1bc7d04d8ee9e96e05d31 Mon Sep 17 00:00:00 2001 From: Joseph Nelson Date: Wed, 29 Apr 2026 22:17:03 -0700 Subject: [PATCH] updating how I am reading images --- createCollectionsFromCSVs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/createCollectionsFromCSVs.js b/createCollectionsFromCSVs.js index 6f9b863..391b7cd 100644 --- a/createCollectionsFromCSVs.js +++ b/createCollectionsFromCSVs.js @@ -99,7 +99,7 @@ async function downloadTcgImage(productId, imageUrl) { return {}; } } -const applyImageToItem = async (itemId, localImagePath, token) => { +const applyImageToItem = async (itemId, localImagePath, fileName, token) => { try { console.log(`Local Image Path: ${localImagePath}`); @@ -109,7 +109,7 @@ const applyImageToItem = async (itemId, localImagePath, token) => { } const formData = new FormData(); - formData.append(localImagePath, fs.readFileSync(localImagePath)); + formData.append('image', fs.readFileSync(localImagePath), filename); const response = await fetch(`${koillectionBaseUrl}/items/${itemId}/image`, { method: 'POST', headers: { @@ -211,7 +211,7 @@ const createCollectionFromCSV = async (name, csvFilePath) => { // Await each download before starting the next // const { destination } = await downloadTcgImage(productId, item.imageUrl); - item.itemIds.forEach((id) => itemIdImageLocations.push({ itemId: id, imageDest: path.join(imagesDir, `${productId}.jpg`) })); + item.itemIds.forEach((id) => itemIdImageLocations.push({ itemId: id, imageDest: imagesDir, fileName: `${productId}.jpg` })); } // After processing all collections, check the imagesDir @@ -221,7 +221,7 @@ const createCollectionFromCSV = async (name, csvFilePath) => { console.log(`Item ID Image Locations: ${JSON.stringify(itemIdImageLocations, null, 2)}`); // Process multiple images concurrently using Promise.all() const promises = itemIdImageLocations.map(async (item) => { - await applyImageToItem(item.itemId, item.imageDest, token); + await applyImageToItem(item.itemId, item.imageDest, item.fileName, token); }); await Promise.all(promises); };