Trouble with Programmatically Updating Media URLS in API to Cloudfront domain URL

Hi I have S3 & cloudfront video storage which is uploaded to via the media section in strapi…
I then want to access the cloudfront files on the front end by updating the urls in the API before they are served to the front.

my problem is in trying to programmatically update the URLS in the API to be a cloudfront domain rather than an s3 domain… I have created a lifecycles file in my content api under the following…

  afterUpdate: async (event) => {
    if (event.result.video) {
      let  VideoList = event.result.video

      for (let i = 0; i < event.result.video.length; i++){
        VideoList[i].url = VideoList[i].url.replace( '[OLD URL]', '[CLOUDFRONT URL]' )
      }

      console.log(VideoList)

      strapi.query('api::home-page.home-page').update({
        where: { id: event.result.id },
        data: {
          video: VideoList
        },
      });
    }
  }
};

logging the video list results in showing that my VideoList has in fact been updated with the correct urls, so my problem lies with that strapi.query.update method…

im pretty sure its all correct according to these examples but im just at a dead end:

any help would be greatly appriciated! :smile:

This topic has been created from a Discord post (1225476701522231477) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

You know what… Ive just noticed that the other fields arent updating either… or atleast the frontend is showing old versions of them all

Dude restack io is some chat gpt nonsense scam

Do you uploading an video

Or you are using a url?

So you are modding the uploaded video url

That way you are never going to get it lol

The problem is db.query is low level api

You won’t update from api::home-

Only if you directly hit the media library

the video is already uploaded to cloudfront, all I wanna do is use the media selector in the admin, have the client select the videos then have that video corrospond to the vid of the same name from the s3 using cloudfront

With plugin::upload.file you may try

Well to do that properly you need to do extension to upload file content type

Add some field like cloudfrontSrc

yeah ive handled the upload stuff with :

  // ...
  upload: {
    config: {
      provider: 'aws-s3',
      providerOptions: {
        s3Options: {
          credentials: {
            accessKeyId: env('AWS_ACCESS_KEY_ID'),
            secretAccessKey: env('AWS_SECRET'),
          },
          region: env('AWS_REGION'),
          params: {
            ACL: env('AWS_ACL', 'private'), // Adjust if needed (private)
            Bucket: env('AWS_BUCKET'),
          },
        },
      },
    },
  },
  // ...
});

but its just the act of when the client selects the media from the admin, it corrosponds to the same media that is from cloudfront… so my approach was to modify the url before its served to the front end so it contains the cloudfront string instead of the old url

That’s a middleware

What you are trying to do currently is to break url of video in admin panel

It might be accessible from frontend after but might break in admin panel

im gonna be honest ive just been winging it

Well route middleware is access to content before it send to front