[英]How to upload a base64 image URL to Firebase and retrieve its access token?
[英]Why is it that when I upload a base64 image to firebase it shows in storage with extension application/octet
基本上,我有一个 base64 图像,我想上传到 firebase 存储,但每当我这样做时,它最终都会有一个“应用程序/八位字节”扩展名,这不是我所期望的,我哪里出错了?
Function处理上传到firebase存储
const handleFiles = (files) => {
if(files == null) return;
const imageRef = ref(storage, `images/${v4()}`);
//Upload image to firebase
uploadBytes(imageRef, files.base64.slice(23)).then(() => {
alert("Image Uploaded")
})
}
如文档中所述,
如果未指定
contentType
元数据并且文件没有文件扩展名,则 Cloud Storage 默认为application/octet-stream
类型。 另外,尝试使用uploadString()
上传base64
字符串而不是uploadBytes()
尝试指定文件的contentType
,如下所示:
uploadString(imageRef, files.base64.slice(23), 'base64', {
contentType: 'image/png', // <-- replace with file's type
}).then(() => {
alert('Image Uploaded')
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.