我有一个名为 imgBase64
的 Base64 编码图像。
如何使用 Fetch API 从浏览器通过 HTTP PUT 此 PNG?
const response = await fetch(url, {
method: 'put',
headers: {
'Content-Type': 'image/png'
},
body: atob(imgBase64) // <--------- what should I be doing here?
});
最佳答案
如果 imgBase64
已经编码,您可以添加 Content-Transfer-Encoding
header 并删除 atob
方法:
const response = await fetch(url, {
method: 'put',
headers: {
'Content-Type': 'image/png',
'Content-Transfer-Encoding': 'base64'
},
body: imgBase64
});
关于javascript - HTTP 使用 Fetch API 放置 PNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63062936/