将文件上传到 strapi 实体中的组件数组

upload a file to an array of component in an entity in strapi

我有一个集合,其中有一个组件数组 product_licenses,它与图像一起获取数据。 如果我将图片上传到 Lis 标签,它就可以工作。但是当我尝试使用 license 标签上传到数组的第一个元素时,它失败了,因为它在里面。

const entity = await strapi.services[
            'product-registration'
          ].create(input);

          if (lis) {
            // automatically uploads the files based on the entry and the model

            // eslint-disable-next-line max-len
            await strapi.plugins.upload.services.upload.uploadToEntity({
              id: entity.id || entity._id,
              model: 'product-registration',
              field: 'lis'
            }, lis);

            await strapi.plugins.upload.services.upload.uploadToEntity({
              id: entity.id || entity._id,
              model: 'product-registration',
              field: 'product_licenses[0].license'
            }, lis);
          }

有什么办法可以实现吗?

为了link将上传的图片上传到组件字段,您应该按如下方式设置params参数:

  • id: product_license 组件id
  • model:这里要拼接组件的类别名+组件名 (category_name.product_license)
  • 字段:你的组件图片字段名