what i want to do is upload the image first the save the link to a user in db.
This is my graphql resolver:
resolve: async (_root, args, { user, prisma }) => {
....
const params = {
Bucket: s3BucketName,
Key: fileName,
ACL: 'public-read',
Body: file.createReadStream(),
ContentType: file.mimetype,
};
return s3.putObject(params, async function (error, data) {
if (error) {
return {
message: error,
success: false,
};
} else {
// user has updated
if (user.profileImg)
return prisma.user
.update({
where: { id: Number(user.id) },
data: {
profileImg: fileName,
},
})
.then(
(response) => {
console.log('response: ', response);
return {
message: 'Success',
success: true,
};
},
(error) => {
return {
message: error,
success: false,
};
}
);
else {
return {
message: 'Success',
success: true,
};
}
}
});
},
what i want to do is return from s3, but my problem is i think it returns without this resolving and returns null so emmage and success is not returned. how do i construct a function resolver using s3?