flamelink-js-sdk
flamelink-js-sdk copied to clipboard
Feature request: Get multiple image sizes for populated fields
I have a schema 'realizations' with field 'images'. For every image I want a small and a large image to use in a lightbox. I managed to do this with a workaround:
this.realisations = await this.flamelinkService
.getApp()
.content.get({
schemaKey: 'realizations',
fields: ['date', 'category', 'images'],
populate: [
'category',
{
field: 'images',
size: {
width: 375,
height: 9999,
quality: 1
}
}
]
})
.then(results => {
if (!results) {
return [];
}
results = Object.values(results);
results.map(result =>
result.images.map(async image => {
image.largeUrl = await this.flamelinkService.getApp().storage.getURL({
fileId: image.id,
size: {
width: 1440,
height: 9999,
quality: 1
}
});
return image;
})
);
return results;
});
A better solution, as suggested by @jperasmus , would be to use a an array of sizes to the populate field:
sizes: [
{
width: 375,
height: 9999,
quality: 1
},
{
width: 500,
height: 9999,
quality: 1
}
]
Which then returns the entries with a sizes array that includes the url for each size.
I think good solution to this would be if the image URL's for each size could be cached on the document so they are downloaded with the original request, that way there is no need to specify an array of sizes on the request and there is no additional network ingress from the internal call to getDownloadUrl() which I am finding a bottleneck. This solution would also make using srcset trivial.
I would also like to know if its possible to implement this feature. It'd be great.
@gitdubz Can you please let us know if you're adding this in near future ?
Hi @nrgnrg @thelazyindian
I will investigate what changes need to be made. From an ease of use perspective this makes sense. In the event that we do make the changes for this functionality it would make sense to handle an array of sizes to populate the value.
In addition to this, an update to the schema builder will be done later this year to choose between storing file/image data as a reference or the value itself. This will reduce network calls as mentioned, but can also cause issues if access tokens are revoked or expire. We are looking into the last part before making these changes in the CMS.
Good to know!