我尝试了多种方法,最终创建了一个上传到Cloudinary的网络摄像头。有没有办法把这些图片从Cloudinary上传到firebase?如果没有,我们可以在react.js中创建一个可以上传到firebase数据库的摄像头吗?
发布于 2020-07-24 18:24:22
不确定cloudinary,因为我从未使用过它,但你可以在react应用程序中添加摄像头,然后将图像保存为blob,然后使用它将图像保存到firebase存储中。
要打开相机,请使用带有文件类型和捕获属性的input元素
<input
type="file"
accept="image/*"
capture
/>在通过相机拍摄图像时,你可以创建它的URL,这是在文件输入的onchange方法中
const {
target: { files },
} = e;
const imageUrl = window.URL.createObjectURL(files[0]);现在从URL创建一个blob
let resFront = await fetch(imageURL);
let tempblobFront = await resFront.blob();然后将blob保存到firebase存储
firebase
.storage()
.ref(put your folder name in firebase storage here)
.child(put name by which you want to save the image)
.put(put your image blob over here i.e tempblobFront)
.then((res) => res)
.catch((err) => {
console.log(err);
}),发布于 2020-07-25 05:05:15
你可能想试试cloudinary upload小部件:https://cloudinary.com/documentation/upload_widget,它包括相机,本地驱动器,谷歌照片等等。
https://stackoverflow.com/questions/63067296
复制相似问题