使用此代码,我可以上传文件,但无法获得有效载荷响应,即新文件的base64表示形式。
bash $ SEARCH="SOMETEXT"
bash $ <file.json jtc -w"<$SEARCH>R:[-3]"
{
"id": 729384872903,
"notes": [
{
"body": "Some more more normal text [SOMETEXT]",
"id": 983012
},
{
"body": "Some more more more normal text",
"id": 89023432
}
]
}
bash $
我尝试了不同的this.http.post(config.url, formData, {
reportProgress: true,
responseType: 'arraybuffer'
}).subscribre(res => {
console.log(res);
});
(responseType
,blob
,arraybuffer
和text
),但是在任何情况下我都无法获得有效载荷中的base64。
编辑1: 在Web控制台中,响应为bse64字符串
但是json
返回:
subscribe
,如果ArrayBuffer: {bytelength: 3717}
是responseType
arraybuffer
,如果Blob: {size: 3717, type: 'application/octet-stream'}
是responseType
blob
是responseType
的请求正文text
是responseType
则错误答案 0 :(得分:0)
我只需要将ArrayBuffer转换为base64字符串
const base64= btoa(String.fromCharCode.apply(null, new Uint8Array(res)));