updating how I set form data for fetch
Build and Push Image / build-and-push (push) Successful in 8m20s
Build and Push Image / build-and-push (push) Successful in 8m20s
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const csvParser = require('csv-parser');
|
const csvParser = require('csv-parser');
|
||||||
|
const { readFile } = require('node:fs/promises');
|
||||||
|
const { basename } = require('node:path');
|
||||||
const koillectionBaseUrl = 'https://koillection.nelson-household.com/api'; // Verify this URL
|
const koillectionBaseUrl = 'https://koillection.nelson-household.com/api'; // Verify this URL
|
||||||
const authenticationUrl = `${koillectionBaseUrl}/authentication_token`; // URL to obtain JWT
|
const authenticationUrl = `${koillectionBaseUrl}/authentication_token`; // URL to obtain JWT
|
||||||
const imagesDir = path.join(__dirname, 'master-set-images/perfect-order'); // Use __dirname for correct path
|
const imagesDir = path.join(__dirname, 'master-set-images/perfect-order'); // Use __dirname for correct path
|
||||||
@@ -108,13 +110,14 @@ const applyImageToItem = async (itemId, localImagePath, fileName, token) => {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileData = await readFile(path.join(localImagePath, fileName));
|
||||||
|
const fileNameBase = basename(path.join(localImagePath, fileName));
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('image', new Blob([fs.readFileSync(path.join(localImagePath, fileName))], { type: 'image/jpg' }), fileName);
|
formData.append('file', new Blob([fileData], { type: 'image/jpg' }), fileNameBase);
|
||||||
const response = await fetch(`${koillectionBaseUrl}/items/${itemId}/image`, {
|
const response = await fetch(`${koillectionBaseUrl}/items/${itemId}/image`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${token}`,
|
'Authorization': `Bearer ${token}`,
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
},
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user