[英]Why is it that when I upload a base64 image to firebase it shows in storage with extension application/octet
Basically, I have a base64 image that I want to upload to firebase storage but whenever I do that, it ends up having a "application/octet" extension which is not what i was expecting, where am I going wrong?基本上,我有一个 base64 图像,我想上传到 firebase 存储,但每当我这样做时,它最终都会有一个“应用程序/八位字节”扩展名,这不是我所期望的,我哪里出错了?
The Function handling the upload to firebase storage 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")
})
}
As mentioned in the documentation ,如文档中所述,
If no
contentType
metadata is specified and the file doesn't have a file extension, Cloud Storage defaults to the typeapplication/octet-stream
.如果未指定
contentType
元数据并且文件没有文件扩展名,则 Cloud Storage 默认为application/octet-stream
类型。 Also, try usinguploadString()
to uploadbase64
strings instead ofuploadBytes()
另外,尝试使用
uploadString()
上传base64
字符串而不是uploadBytes()
Try specifing the contentType
of your file as shown below:尝试指定文件的
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.