javascript - 在 nodejs 和 vuejs 的文件夹中获取我保存的图像名称时出错
问题描述
我使用 multer 中间件上传了我的图片
const storage = multer.diskStorage({
destination: function(req, file, cb) {
// fs.mkdir('../uploads/', (err) => {
cb(null, './public/images/')
// console.log(err)
},
filename: function(req, file, cb) {
cb(null, `${Date.now()}-hemmyhtec-${file.originalname}`)
}
})
const fileFilter = (req, file, cb) => {
if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
cb(null, true)
} else {
cb(null, false)
const error = new Error('Wrong File, only image are allowed')
console.log(error)
}
}
我的图像已保存到文件夹中,并将名称作为文件保存到数据库中:(“1632760261507-hemmyhtec-1.png”)。
It added "\" at the beginning \"" and also at the end of the file name.
在获取我的 vuejs 代码时,这给了我一个错误
谁能告诉我问题或更好的方法?
创建文件的代码...
const file = req.file;
MentorProfile.create({
file: file.filename,
profession: req.body.profession,
about: req.body.about.....
解决方案
推荐阅读
- java - 如何获取指定关键字在 iText7 中的位置?
- c# - 从数据库中检索具有名称的图像到 ListView
- python - Python mock 与 unittest.mock 补丁
- spring-boot - 我可以通过spring security在我的spring boot应用程序中使用两个不同的表登录吗?
- c++ - C++:如何优化标准布局类模板中的空数据成员?
- logging - 在 Gunicorn 中记录所有请求和响应标头
- java - Java(SQL Like)和Shell脚本运行2个参数的问题
- python - 打开另一帧后如何在第一帧运行程序?
- powershell - Get-ADGroup "myADgroup" -Properties myProperty - 解析输出并仅获取 CN
- asp.net-core - 如何检查 asp.net 核心方法?