我已经放弃尝试从文件系统URL加载它,现在尝试使用base64。
<meta http-equiv="Content-Security-Policy" content="
default-src *;
style-src * 'unsafe-inline';
script-src * 'unsafe-inline' 'unsafe-eval';
media-src *;
img-src * data:;
connect-src * ws: wss:;
" />
“拒绝连接到”数据:image/jpg;base64。。。因为它违反了
文档的内容安全策略。”,来源:
http://localhost:8080/js/main.js
"
有人知道为什么会这样,或者我会如何着手解决这个问题吗?
navigator.camera.getPicture(response => {
this.urltoFile('data:image/jpg;base64,'+response, 'test.jpg')
.then(file => {
console.log(file);
})
}, () => {}, {
destinationType : navigator.camera.DestinationType.DATA_URL,
})
urlToFile
功能是:
urltoFile(url, filename){
let mimeType = (url.match(/^data:([^;]+);/)||'')[1];
return (fetch(url)
.then(res => {
return res.arrayBuffer();
})
.then(buf => {
return new File([buf], filename, {
type: mimeType
});
})
);
}