base64 编码图像主机 url 或服务器文件路径
base64 encode image host url or server file path
当我将图像数据编码为 base64 字符串时,我使用服务器文件路径通过 fs.readFile()
获取图像数据。我有疑问:这是否意味着其他人可以解码 base64 字符串,然后从编码数据中获取服务器路径,如下所示?
...
fs.readFile(destinationFilePath, function(error, data){
fulfill(data.toString('base64'));
});
我不想泄露我的服务器路径,所以我也尝试像下面的代码一样对主机进行编码 url,我不确定这种使用 base64 的正确方法?我没有收到任何错误,但也没有收到任何回复 - 我是不是漏掉了什么?
var base64EncodeData = function(destinationFilePath) {
return new Promise(function (fulfill, reject){
var request = require('request').defaults({ encoding: null });
request.get(destinationFilePath, function (error, response, body) {
if (!error && response.statusCode == 200) {
data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');
console.log(data);
fulfill(data);
}
});
});
};
否 你不会通过 base64 编码图像泄露你的服务器路径。您生成的 base64 仅包含二进制图像数据的 base64 表示。实际上,通过对它们进行 base64 编码,当您在 HTML 页面中显示它们时,您可以删除对路径的任何使用,例如:
<img alt="base64 image" src="data:image/png;base64,isdRw0KGgot5AAANdSsDIA..." />
src 属性包含正在提供数据的标志data:
文件 mimetype image/png;
编码 base64,
和编码图像数据 isdRw0KGgot5AAANdSsDIA...
.
当我将图像数据编码为 base64 字符串时,我使用服务器文件路径通过 fs.readFile()
获取图像数据。我有疑问:这是否意味着其他人可以解码 base64 字符串,然后从编码数据中获取服务器路径,如下所示?
...
fs.readFile(destinationFilePath, function(error, data){
fulfill(data.toString('base64'));
});
我不想泄露我的服务器路径,所以我也尝试像下面的代码一样对主机进行编码 url,我不确定这种使用 base64 的正确方法?我没有收到任何错误,但也没有收到任何回复 - 我是不是漏掉了什么?
var base64EncodeData = function(destinationFilePath) {
return new Promise(function (fulfill, reject){
var request = require('request').defaults({ encoding: null });
request.get(destinationFilePath, function (error, response, body) {
if (!error && response.statusCode == 200) {
data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');
console.log(data);
fulfill(data);
}
});
});
};
否 你不会通过 base64 编码图像泄露你的服务器路径。您生成的 base64 仅包含二进制图像数据的 base64 表示。实际上,通过对它们进行 base64 编码,当您在 HTML 页面中显示它们时,您可以删除对路径的任何使用,例如:
<img alt="base64 image" src="data:image/png;base64,isdRw0KGgot5AAANdSsDIA..." />
src 属性包含正在提供数据的标志data:
文件 mimetype image/png;
编码 base64,
和编码图像数据 isdRw0KGgot5AAANdSsDIA...
.