Hi
Are there any docs on how use uploadFile to import multiple files to an asset gallery?
my code looks like
const gallery = await client.uploadFile(
plan.gallery[0], {
defaultFieldMetadata: {
en: {
alt: '',
title: '',
focalPoint: {
x: 0.5,
y: 0.5,
},
customData: {
watermark: false
}
}
},
notes: '',
}
);
gallery
is an array of remote image urls…
This works for a single file but guessing i need to change it for asset galleries
1 Like
Hello @jacktcunningham_publisher
For the moment you can’t upload more than one file per request, so you must do more than one request if you want to do more than one file.
In your case you would have to
for(file of plan.gallery){
const uploadedFile = await client.uploadFile(
file, {
defaultFieldMetadata: {
en: {
alt: '',
title: '',
focalPoint: {
x: 0.5,
y: 0.5,
},
customData: {
watermark: false
}
}
},
notes: '',
}
}
There is a feature request for bulk uploads here: Some Requests
But for now, you can only upload one file per reuquest
Ok, that doesn’t work, it looks like it overwrites the object on each loop rather than adding to it… but I think I know what i need to do, thanks
This solved it in the end, thanks
async function importPlans() {
let uploadedGallery = [];
for (let plan of plans) {
const uploadedCover = await client.uploadFile(
for(file of plan.gallery) {
var temp = await client.uploadFile (
file, {
defaultFieldMetadata: {
en: {
alt: '',
title: '',
focalPoint: {
x: 0.5,
y: 0.5,
},
customData: {
watermark: false
}
}
},
notes: '',
}
);
uploadedGallery.push(temp);
};
plan[plan.name] = await client.items.create({
...
gallery: (uploadedGallery ? uploadedGallery : null)
});
}
}
1 Like