node.js - URIError:无法解码参数 - 编码二进制图像 Filepond
问题描述
我将图像作为 type:binary 发送并解析为 JSON 到数据库,其中它是一个 json 字符串。如果我想查询图像,它会引发错误
URIError:无法在 decodeURIComponent () 处解码参数“%EF%BF%BD...”
我按如下方式保存对图像进行编码:在模型文件夹中:
...
paintings: { type: Buffer },
paintingsType:{ type: String }
postSchema.virtual('paintingsP').get(function() {
if (this.paintings != null && this.paintingsType != null) {
return `data:${this.profilpicType};charset=utf-8;base64,${this.profilpic.toString('base64')}`
}
})
在 router.js 内部
// **Inside a router.put function**
...
if (req.body.paintings != null && req.body.paintings !== '') {
savePaintings(post, req.body.paintings)
}
function savePaintings(post, profilpictureEncoded) {
if (profilpictureEncoded == null) return;
const profpic = JSON.parse(profilpictureEncoded);
if (profpic != null && imageMimeTypes.includes(profpic.type)) { // If the file is a json obj & from the type image (jpg, png)
post.paintings = new Buffer.from(profpic.data, 'base64') // Buffer.from(where, how)
post.paintingsType = profpic.type
}
}
await post.save();
如果我查找所有接缝都很好,那么问题可能出在哪里?我的要求有错吗?数据库内部:
我使用 express、mongoose、ejs 和 FilePond (用于保存文件)。
解决方案
推荐阅读
- javascript - 如何使用 JS 模板中的 TypeScript 添加指令?
- checkbox - How to check a checkbox without unchecking?
- python - Tensorflow Advanced Indexing: Assign a smaller tensor into a bigger one into a position based on two index tensors
- html - MouseLeave event not firing for anchor and other inline elements
- python - Why am I getting a ModuleNotFoundError when using googletrans
- elasticsearch - Logstash 到 elasticsearch ssl 配置
- for-loop - Sorted for-each loop in XSLT can not reference nodes to XPath query outside of loop
- sql - 垂直报告标题
- javascript - Changing classList results in an Uncaught TypeError Failed to set an indexed property
- java - How to break out of while loop after taking in all the inputs?