Know if a response has a media property/entity before return

Hi,
Is there any way to know for each request if the response has a media property/entity before return?
I want to get each media url from each response of any request.

I have seen all the middleware of strapi package, but I don’t know if middleware is the best option.

Thanks

System Information
  • Strapi Version: 3.6.8
  • Operating System: Linux
  • Database: MySQL
  • Node Version: 14
  • NPM Version: 6
  • Yarn Version: 1.22

What way are you trying do this ?
Front → Back ? You can always check the body / header etc if it does not have it correctly
Back → Front ? You can get it from the database then loop over it if more then one, and if it does exist return it ?

All this is for local development.

When api strapi receives a request, i want backend to see if the response have any media field, and download each file from production project.

Basically get production files on a development server on demand.

Then, I dont know where to put an event in Strapi backend to resolve this.

Thanks

So then it would be the first one.
Check the body / header of the request if have any media fields. if you log out ctx you should see it im guessing in the body. Where you can then do further get requests etc.

I would say if you dont have it create a custom endpoint where you can deal with this. You can also extend the upload endpoint etc. To do the checks you want.

I want to do the same thing that this drupal module does.
https://www.drupal.org/project/stage_file_proxy

strapi.router.get('*', async (ctx, next) => {
      console.log('Middleware GET', {ctx});
      await next();
      console.log('Middleware END', {ctx});
})

This code is in the middleware for each request and in the headers I cannot see if there are any fields of type media.

I would have to iterate all the rows to see if there are any fields of type media.

Maybe I can take the entity structure and see what types of fields it has.

Is this a good idea?

Well again looking at the headers you can look for things like
Content-Type: multipart/form-data; As an example

Hi!!

Sorry for not explaining myself well.

Finally I found solution and I make this plugin.

Thanks