如何将 YAML 文件作为 base64 编码字符串发送?
How do I send a YAML file as a base64 encoded string?
我正在尝试将 yaml 文件作为 base64 字符串发送,以便此代码有效:
const response = await octokit.request('GET /repos/{owner}/{repo}/git/blobs/{file_sha}', {
owner: 'DevEx',
repo: 'hpdev-content',
file_sha: fileSha,
headers: {
authorization: `Bearer ${githubConfig?.token}`,
},
});
const decoded = Buffer.from(response.data.content, 'base64').toString('utf8');
在上面的代码中response.data.content
应该有数据。
我有这条路线:
router.get('/repos/:owner/:repo/git/blobs/:file_sha', (req, res) => {
// TODO: do we need to do anything with the path params?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { owner, repo, file_sha } = req.params;
const contents = writeUsersReport();
const encoded = Buffer.from(contents, 'binary').toString('base64');
res.send(encoded);
});
除了客户端代码需要在以下代码中称为 content
的 属性 中的 base64 字符串外,代码工作正常:
const decoded = Buffer.from(response.data.content, 'base64').toString('utf8');
但是字符串在response.data
中。
我怎样才能设置 content
属性 呢?
如何从您的服务器端发送包含带有 content
属性 对象的 json 响应而不是直接发送编码字符串?
// ...
const encoded = Buffer.from(contents, 'binary').toString('base64');
res.json({content:encoded});
我正在尝试将 yaml 文件作为 base64 字符串发送,以便此代码有效:
const response = await octokit.request('GET /repos/{owner}/{repo}/git/blobs/{file_sha}', {
owner: 'DevEx',
repo: 'hpdev-content',
file_sha: fileSha,
headers: {
authorization: `Bearer ${githubConfig?.token}`,
},
});
const decoded = Buffer.from(response.data.content, 'base64').toString('utf8');
在上面的代码中response.data.content
应该有数据。
我有这条路线:
router.get('/repos/:owner/:repo/git/blobs/:file_sha', (req, res) => {
// TODO: do we need to do anything with the path params?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { owner, repo, file_sha } = req.params;
const contents = writeUsersReport();
const encoded = Buffer.from(contents, 'binary').toString('base64');
res.send(encoded);
});
除了客户端代码需要在以下代码中称为 content
的 属性 中的 base64 字符串外,代码工作正常:
const decoded = Buffer.from(response.data.content, 'base64').toString('utf8');
但是字符串在response.data
中。
我怎样才能设置 content
属性 呢?
如何从您的服务器端发送包含带有 content
属性 对象的 json 响应而不是直接发送编码字符串?
// ...
const encoded = Buffer.from(contents, 'binary').toString('base64');
res.json({content:encoded});