How to add custom fields to Media / Assets

System Information
  • Strapi Version: 4.3.9

We currently evaluate strapi as our go-to headless-cms due to its flexibility. One requirement we need is the ability to add custom fields to media in the media library (e.g. copyright notice)

Its ok if this is only possible via a custom plugin, but unfortunatly i don’t find any hint in the docs how to do this.

Any inputs how to do that?

(also strapi - How to add custom properties to media field - Stack Overflow is unanswered)

1 Like

You can add via plugin or via /src/index.js in the register function. Change “customFieldName” to what ever custom field you want to create.

    strapi.contentType("plugin::upload.file").attributes.customFieldName = {
      type: "text",
    };

Thank you,

i tried that, restarted, but i see no effect. Is there something missing?

EDIT: i toyed around and try to delete an existing field, e.g.:

delete strapi.contentType("plugin::upload.file").attributes.alternativeText

This results in the field still be there, just empty. That looks very like the form in the asset library is hard-coded and does not support custom fields. :worried:

So it does not seem to be possible I guess? At least not without hacking into the Admin-UI ?

I’m looking for this feature as well. Anyone else have a solution? We need to have a field that we can hold some params for passing to the image CDN on a per asset basis. Seems like a pretty common use case.

I’ve asked in Discord a few times as well w/ no response.

@ericprice or @Marco_Wettstein did you find out?

No. I’ve not figured out how to add fields to Media assets. I’ve come up with a workaround for what I needed it for by using component but it would be better to have custom fields available right on the media assets that come along in the API requests for any assets using them.

Hey, any updates on that?
We are using a patch-package to add extra asset fields(more alternative texts). But from Strapi v4.15.1 patch-package doesn’t work. So we need to work with the older version or change patch-package feature

I’m also interested! It could be very useful in many different scenarios.