我正在嘗試將 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屬性?
uj5u.com熱心網友回復:
如何content從服務器端發送一個包含具有屬性的物件的 json 回應,而不是直接發送編碼字串?
// ...
const encoded = Buffer.from(contents, 'binary').toString('base64');
res.json({content:encoded});
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/378327.html
標籤:javascript 节点.js 表达 雅姆
上一篇:使用帶連字符的@SerializedName不起作用
下一篇:exphbs不是函式
