-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Labels
issue: bugIssue reporting a bugIssue reporting a bugseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solveIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: core:uploadSource is core/upload packageSource is core/upload packagestatus: confirmedConfirmed by a Strapi Team member or multiple community membersConfirmed by a Strapi Team member or multiple community members
Description
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
strapi/packages/strapi/lib/services/utils/upload-files.js
Lines 57 to 67 in b2b4515
| 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)));
},robots4life, reppard, AdrianoCahete and lundgren2
Metadata
Metadata
Assignees
Labels
issue: bugIssue reporting a bugIssue reporting a bugseverity: lowIf the issue only affects a very niche base of users and an easily implemented workaround can solveIf the issue only affects a very niche base of users and an easily implemented workaround can solvesource: core:uploadSource is core/upload packageSource is core/upload packagestatus: confirmedConfirmed by a Strapi Team member or multiple community membersConfirmed by a Strapi Team member or multiple community members