Images created with migration.createAsset are not considered as images

Following the migration API docs, I'm doing the following :

migration.createAsset(fs.readFileSync(imagePath), 'test.webp')

The migration runs smoothly and I can see the new media in media library. However there is no preview, and I cannot use it in a ImageField :


Note that the file is not corrupted, if I download it from the media library, it is identical to my original image.

Strangely, if I host the image somewhere and do the exact same, it works fine :

migration.createAsset('https://www.example.com/test.webp', 'test.webp')

I'm not sure what's going wrong here ?

Regards,
Grégoire

Hi Grégoire,

Is it happening specifically to this image, and no other? Are other .webp assets working fine?

Let me know!

Hi Ezekiel,

Every single image on more than 800.
When i read them on the filesystem with fs.readFileSync (Node22), this is the result. I kept one on our repo if you want to check it.

Once I hosted the same images online, I was able to import all of them without a single failure.

Regards,
Grégoire

Hi @gbelorgey,

I'm not entirely sure what's causing the issue in this case. I'm going to try to recreate this and investigate it on my own, I'll get back to you with news of how that goes!

For the time being, a good workaround is to apply Imgix URL parameters when rendering the image on your site. Imgix powers Prismic’s image URLs and supports format conversion on-the-fly using a simple ?fm=jpg parameter.

For example, if your image URL is:

https://images.prismic.io/your-repo/image-id.webp

You can convert it to .jpg like this:

https://images.prismic.io/your-repo/image-id.webp?fm=jpg

If you’re rendering the images dynamically, we recommend building a helper function that appends fm=jpg (and other Imgix params if needed) at runtime — this gives you full control over the format, compression, and sizing without modifying your migration logic.

Let me know if that helps!

hi @Ezekiel

The thing is, because the image is not identified as an image by the media library, I cannot assign it to an ImageField. So it's not really possible to use it in any meaningful way..

Regards,
Grégoire

Hi @gbelorgey,

This makes sense. Short of converting your images before migration, I'm not entirely sure what alternative I can provide here. However we have recreated the issue on our side and are looking at potential ways to fix it. I don't have a precise timeline, but the team is on it. Sorry for the inconvenience in the meantime! I'll keep you updated here when it's fixed.

1 Like