我在从 Google 脚本网站访问相机时遇到问题。
我已经尝试过
<input type="file" accept="image/*" id="file-input">
和
<input type="file" accept="image/*;capture=camera">
但两者都会打开文件管理器来选择文件,而不是请求相机权限。
有没有办法使用 Google Script webapp 捕获图像并上传到 google 驱动器。
我尝试过 Google Picker API,但不幸的是它给了我源错误。
谢谢
最佳答案
使用 MediaDevices.getUserMedia(constraints) 方法触发授权流程。配置约束参数来描述请求的媒体类型,例如
var constraints = {video: true, audio: true};
添加
<video id="video" width="640" height="480" autoplay></video>
<script>
var video = document.getElementById('video');
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
video.srcObject = stream;
video.play();
})
.catch(function(err) {
console.log("An error has occured: " + err);
});
</script>
请参阅文档了解更多详细信息 https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
我已在我的 GAS Web 应用程序中测试了上述内容。
关于javascript - 从 Google Script 网站访问相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50232669/