I know there is a method strapi.plugins.upload.services.upload.update()
but how do you actually invoke it? I would like to update file’s caption and altText by its ID
the service you are looking for is:
async updateFileInfo(id, { name, alternativeText, caption }, { user } = {}) {
const dbFile = await this.fetch({ id });
if (!dbFile) {
throw strapi.errors.notFound('file not found');
}
const newInfos = {
name: _.isNil(name) ? dbFile.name : name,
alternativeText: _.isNil(alternativeText) ? dbFile.alternativeText : alternativeText,
caption: _.isNil(caption) ? dbFile.caption : caption,
};
return this.update({ id }, newInfos, { user });
},
You would call it with strapi.plugins.upload.services.upload.updateFileInfo(id, { name, alternativeText, caption }
2 Likes