gpt4 book ai didi

mysql - 从数据库调用后,我的 Base64 图像以不同的格式返回

转载 作者:行者123 更新时间:2023-11-29 17:48:21 28 4
gpt4 key购买 nike

我使用 mySQL 数据库以 base64 格式存储图像,当我从数据库检索图像时,它返回以下格式。这不是我插入数据库的内容,也不适合我希望使用 Base64 代码的函数。我不知道它会像这样返回什么,也不知道如何修复它。如果有人能告诉我发生了什么事,那就太好了,谢谢!

在 Node.js 中处理数据库事务的 get 和 post 请求:

    router.get('/:image', (req, res, next) => {
var values = [
[req.params.image]
];
var sql = "SELECT image FROM images WHERE name = ? " ;

connection.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("image got " + JSON.stringify(result));
res.send(result);
});

});



router.post('/', (req, res, next) => {
console.log(req.name);
const imageJSON = {
name: req.body.name,
image: req.body.image
};
res.status(201).json({
message: imageJSON
});
var sql = "INSERT INTO images (name, image) VALUES ?";
//Make an array of values:
var values = [
[req.body.name, req.body.image]
];
console.log(req.body.name);
connection.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
});

输出结果:

[{"image":{"type":"Buffer","data":
[100,97,116,97,58,105,109,97,103,101,47,112,110,103,59,98,
97,115,101,54,52,44,105,86,66,79,82,119,48,75,71,103,111,65,65,65,65,78,83,85,104,69,85,103,65,65,66,50,73,65,65,65,87,74,67,65,73,65,65,65,65,106,82,48,65,56,65,65,65,65,67,88,66,73,87,88,77,65,65,67,52,106,65,65,65,117,73,119,70,52,112,84,57,50,65,65,65,75,84,50,108,68,81,49,66,81,97,71,57,48,98,51,78,111,98,51,65,103,83,85,78,68,73,72,66,121,98,50,90,112,98,71,85,65,65,72,106,97,110,86,78,110,86,70,80,112,70,106,51,51,51,118,82,67,83,52,105,65,108,69,116,118,85,104,85,73,73,70,74,67,105,52,65,85,107,83,89,113,73,81,107,81,83,111,103,104,111,100,107,86,85,99,69,82,82,85,85,69,71,56,105,103,105,65,79,79,106,111,67,77,70,86,69,115,68,73,111,75,50,65,102,107,73,97,75,79,103,54,79,73,105,115,114,55,52,88,117,106,97,57,97,56,57,43,98,78,47,114,88,88,80,117,101,115,56,53,50,122,122,119,102,65,67,65,121,87,83,68,78,82,78,89,65,77,113,85,73,101,69,101,67,68,120,56,84,71,52,101,81,117,81,73,69,75,74,72,65,65,69,65,105,122,90,67,70,122,47,83,77,66,65,80,104,43,80,68,119,114,73,115,65,72,118,103,65,66,101,78,77,76,67,65,68,65,84,90,118,65,77,66,121,72,47,119,47,113,81,112,108,99,65,89,67,69,65,99,66,48,107,84,104,76,67,73,65,85,65,69,66,54,106,107,75,109,65,69,66,71,65,89,67,100,109,67,90,84,65,75,65,69,65,71,68,76,89,50,76,106,65,70,65,116,65,71,65,110,102,43,98,84,65,73,67,100,43,74,108,55,65,81,66,98,108,67,69,86,65,97,67,82,65,67,65,84,90,89,104,69,65,71,103,55,65,75,122,80,86,111,112,70,65,70,103,119,65,66,82,109,83,56,81,53,65,78,103,116,65,68,66,74,86,50,90,73,65,76,67,51,65,77,68,79,69,65,117...

插入的代码:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB2IAAAWJCAIAAAAjR0A8AAAACXBIWXMAAC4jAAAuIwF4pT92AAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwl…

最佳答案

我明白了。我设置了数据库,以便将图像存储为 Blob,因此将 Base64 代码存储在 Blob 中将返回二进制输出。我刚刚将其更改为 LONGTEXT 数据类型。

关于mysql - 从数据库调用后,我的 Base64 图像以不同的格式返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49615368/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com