问题描述
我有一个Web应用程序(使用Node.JS,Express,MongoDB和Pug),允许用户上传用户照片。我使用iPhone拍摄的任何照片都会旋转到一边。在进行一些研究时,听起来照片包含“ EXIF”元数据,该元数据包含有关照片显示方式的信息。解决此问题的好方法是什么?这是我用于上传照片的代码:
const multerFilter = (req,file,cb) => {
if (file.mimetype.startsWith('image')) {
cb(null,true);
} else {
cb(new AppError('Not an image! Please upload images only.',400),false);
}
};
exports.uploadUserPhoto = multer({
storage: multerS3({
s3: s3,acl: 'public-read',bucket: 'BUCKETNAME',contentType: multerS3.AUTO_CONTENT_TYPE,fileFilter: multerFilter,transforms: () =>
sharp().resize(250,250).jpeg({
progressive: true,quality: 90,}),key: function (req,cb) {
cb(null,req.user.id + Date.Now().toString());
},}).single('photo');
exports.updateMe = catchAsync(async (req,res,next) => {
if (req.body.password || req.body.passwordConfirm) {
return next(
new AppError(
'This route is not for password updates. Please use /updateMyPassword',400
)
);
}
//2) Filter out field names from req.body that aren't allowed
const filteredBody = filterObj(req.body,'name','email');
if (req.file) filteredBody.photo = req.file.location;
//Update the user data
const updatedUser = await User.findByIdAndUpdate(req.user.id,filteredBody,{
new: true,runValidators: true,});
res.status(200).json({
status: 'success',data: {
user: updatedUser,},});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)