I am trying to create a customized controller to update the user’s profile picture. I send PUT request with form-data that contains the picture. The request goes 200 but the picture cannot be uploaded to the database. How to make it run correctly?
This is the controller:
async updatepfp(ctx){
const { id } = ctx.params;
let entity;
if (ctx.is('multipart')) {
const { files, data } = parseMultipartData(ctx);
entity = await strapi.query('user', 'users-permissions').update({ id: id }, data,{
files,
});
} else {
entity = await strapi.query('user', 'users-permissions').update({ id: id }, ctx.request.body);
}
entity = sanitizeUser(entity);
return entity
}
The route:
{
"method": "PUT",
"path": "/users/updatepfp/:id",
"handler": "User.updatepfp",
"config": {
"policies": [],
"prefix": "",
"description": "Update an existing user's pfp",
"tag": {
"plugin": "users-permissions",
"name": "User",
"actionType": "update"
}
}
},
The request in Postman
On the other hand, I am also thinking to override the existed User.update controller for user-permission, but I can’t know the location of the controller. Where is it?
System Information
- Strapi Version: 3.6.6
- Operating System: Mac OS Big Sur 11.2.3
- Database: MySQL
- Node Version: v14.17.5
- NPM Version: 6.14.14
- Yarn Version: 1.22.17