How to create a media object from image URL programatically

I’m populating a collection using API and have an image URL that I want to attach in the media field on the collection. Is there any way to create a new media object in a controller programmatically if I have an image link? I don’t want the image to uploaded anywhere, it should use the URL reference directly.

2 Likes

Is there a specific provider you are using (that is currently storing the media).

Also going to poke @alexandrebodin @Pierre_Noel and @Convly to get their thoughts. As I understand it, you have existing media in a provider and simply need to add that information to the database without actually fetching the file and re-uploading it.

Thanks @DMehaffy. Your understanding of the issue is correct. I have another tool which uploads the media in S3 bucket and I just need to make a database entry of the media in Strapi without re-uploading it anywhere.

I’m not aware of a default option to handle a case like this but lets see what my backend engineers can provide, I’m sure it’s possible. The only issue I see is if someone tries to upload an Image via Strapi.

Your other system, will this be continuing after your move to Strapi or is it just basically a “one time import”?

any update on this?

Can I receive url and upload it as media file directly by specifying some property?
Or do I have to download the image first and then re upload it to media?

@Chandan_Pednekar
Was facing the same issue. you need to use the Id of the asset as the value for the field. Just like relations.