我正在建立一个移动网站,我想使用Camera API拍照.图像应显示在网站上并上传到服务器.根据MDN上Camera API的介绍,可以使用FileReader或访问网站上的图像并显示window.URL.createObjectURL.我使用iPad(Safari和Chrome)和Android平板电脑(Chrome和Firefox)成功测试了这些可能的解决方案.
FileReader和之间有什么区别window.URL.createObjectURL?我认为window.URL.createObjectURL是更新但不是标准.性能有差异吗?
这是我的 api
https://besticon-demo.herokuapp.com/icon?url=facebook.com&size=80..120..200
当我在邮递员中测试这个时,我得到了 Image..但是我怎么能用axios. 我现在用 Axios 得到了很长的字符串(比如?PNG...)
那么我如何使用该响应来显示图像..
axios.get(RequestURL, { withCredentials: false })
.then(function (response) {
// handle success
console.log(response)
var b64Response = btoa(response.data)
setImageServer('data:image/png;base64,' + b64Response) // not showing image
})
Run Code Online (Sandbox Code Playgroud)
尝试运行时也会出错 btoa
DOMException:无法在“Window”上执行“btoa”:要编码的字符串包含超出 Latin1 范围的字符。
HTML
<img src={ImageServer}/>
Run Code Online (Sandbox Code Playgroud)