javascript - HTTP PUT 一个带有 Fetch API 的 PNG
问题描述
我有一个名为imgBase64
.
如何使用 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
标头和删除atob
方法:
const response = await fetch(url, {
method: 'put',
headers: {
'Content-Type': 'image/png',
'Content-Transfer-Encoding': 'base64'
},
body: imgBase64
});
推荐阅读
- html - 如何在图库中的缩略图之间留出空间,并且在所有浏览器中都相同?
- git - 获取 Azure devops 存储库的 reflog?
- java - 如何使用“;”向各种电话号码发送消息 对于单独的(java android)?
- c++ - 二叉搜索树-删除节点会导致其他方法错误c ++
- python - 设置 simpleRNN 的维度(请提供具有相同第一个维度的数据)
- python - 将嵌套字典与一系列可能值进行比较
- react-router - React-Router 与 window.location 不同步?
- xamarin.forms - Azure 通知中心设备注册
- javascript - 有什么方法可以在单击 div 时在节点 js 服务器中获取价值
- tfs - TFS 2013 Multipipeline 构建类似于 Jenkins