繁体   English   中英

为什么当我将 base64 图像上传到 firebase 时,它在存储中显示扩展名为 application/octet

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM