Upload files to a repeatable component

System Information
  • Strapi Version: 3.5.1
  • Operating System: Windows 10 64 bit
  • Database: Postgres
  • Node Version: 14.15.5
  • NPM Version: 6.14.11
  • Yarn Version: 1.21.1

I have a collection type “product-registration” which has a repeatable component “product_licenses” which has an image filed named license.
Now I have created a custom function which creates a product-registration entry then tries to upload images to the repeatable component.
I am not able to figure out the logic to achieve this.

      const entity = await strapi.services[

        'product-registration'

      ].create(input);

      if (lis) {

        // automatically uploads the files based on the entry and the model

        await strapi.plugins.upload.services.upload.uploadToEntity({

          id: entity.id || entity._id,

          model: 'product-registration',

          field: 'license',

          source: 'product-registration'

        }, lis);

      }

Hi @Anuj_Ramakant_Divkar

In order to link the uploaded image to a component field, you should set the params argument as follows:

  • id: The product_license component id
  • model: Here you have to concat the component’s category name + the component name (category_name.product_license)
  • field: your component image field name

Hope it helps.

Can you explain it more? Like, says I have table ‘users_data’, which have a component called ‘user_attachments’. user_attachments have a repeatable media column named ‘doc_files’, what will be the structure? I am doing this but it does not seem to work.

data.append(‘refId’, user.userDetailId);
data.append(‘ref’, ‘users_data’);
data.append(‘model’, “users_data.user_attachments”);
data.append(‘field’, ‘doc_files’);