Always provide desired sizes in media library formats

Hi!

I recently released a new version of my site where I utilise the medium format provided by the media library. To my surprise it was sometimes missing.

It turns out that some formats are not generated if Strapi deems it unnecessary. Although I understand the sentiment I think that it makes for a so-so API. We now have to add a fallback in case the desired format is not present.

How about always providing small, medium and large? In the case that the image is too small to be in a certain size I propose you use the original url instead. That way the API stays consistent and extra image processing isn’t made.

@soupette / @alexandrebodin did we have a specific requirement for them to be generated (size?)

I believe the breakpoints and requirements are defined here.

Hi, not sure I understand your question @DMehaffy here ?

This is a matter of opinion here.

We consider that giving the original url for a format that will not match is not a good practice (give 500px for a large image when we expect 1000x for ex)
It is to the user to decide weather they want to display the original or display something else. If we return a url for every format you have no way to know it is actually the original. You would need to add more metadata or do comparaisons so that would still require some “processing” to take a decision. In that regard we consider it makes more sense to return what exists and ask the sure to handle the fallback how they see fit.

1 Like

Hi Alex.

Personally I would prefer that all formats are generated. I want the medium size format for my requested resource and I wish I could trust that the API would provide it.

But yeah. I totally get that. Can you link me to the docs explaining how the formats work? I couldn’t find it when I looked for it.

Is there any other alternative that would work without comparisons of the returned response? For example providing what format you want in the url, which would scale up if needed?