Skip to content

Upload during entity creation does not support path, alternativeText, caption, etc. #8467

@reppard

Description

@reppard

Bug report

Describe the bug

When uploading files during entity creation, strapi doesn't send fileInfo or metas to the uploadService. This makes it impossible to set alternativeText or caption for a given file. It also removes the ability set path for custom paths using the S3 upload provider.

Steps to reproduce the behavior

return uploadService.uploadToEntity({ id, model, field }, files, source);

Upload a file during entity creation. Path, alternativeText, and caption will be ignored.

Expected behavior

Should be able to append fileInfo and metas to FormData so attributes like path, alternativeText, and caption can be set during entity creation.

Code snippets

const doUpload = async (key, files) => {
const parts = key.split('.');
const [path, field] = [_.initial(parts), _.last(parts)];
const { model, source } = findModelFromUploadPath(path);
if (model) {
const id = _.get(entry, path.concat('id'));
return uploadService.uploadToEntity({ id, model, field }, files, source);
}
};

// strapi/strapi/blob/master/packages/strapi-plugin-upload/services/Upload.js#L355-L372
  async uploadToEntity(params, files, source) {
    const { id, model, field } = params;

    const arr = Array.isArray(files) ? files : [files];
    const enhancedFiles = await Promise.all(
      arr.map(file => {
        return this.enhanceFile(
          file,
          {}, // fileInfo could be provider here
          {   // could be added here
            refId: id,
            ref: model,
            source,
            field,
          }
        );
      })
    );

    await Promise.all(enhancedFiles.map(file => this.uploadFileAndPersist(file)));
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: bugIssue reporting a bugseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: core:uploadSource is core/upload packagestatus: confirmedConfirmed by a Strapi Team member or multiple community members

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions