Я отправляю изображение в виде типа: двоичный и анализирую в JSON в БД, где это строка json. Если я хочу запросить изображение, оно выдает ошибку
URIError: Не удалось декодировать параметр '% EF% BF% BD ...' в decodeURIComponent ()
Я сохраняю кодирование изображения следующим образом: Внутри папки моделей:
...
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')}`
}
})
Внутри маршрутизатора. 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();
Если я посмотрю все хорошо, то где может быть проблема? Мой запрос неверен? Внутри БД: ![DB](https://i.stack.imgur.com/MriSU.png)
Я использую express, mon goose, e js и FilePond (для сохранения файлов) .