简体   繁体   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

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 type application/octet-stream .如果未指定contentType元数据并且文件没有文件扩展名,则 Cloud Storage 默认为application/octet-stream类型。 Also, try using uploadString() to upload base64 strings instead of uploadBytes()另外,尝试使用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.

相关问题 如何将 base64 图像 URL 上传到 Firebase 并检索其访问令牌? - How to upload a base64 image URL to Firebase and retrieve its access token? Firebase 存储:字符串与格式不匹配 base64:找到无效字符。 仅当调试关闭时 - Firebase Storage: string does not match format base64: invalid character found. Only when debug is off Firebase 存储 | 从 node.js 云函数上传时文件是“application/octet-stream” - Firebase Storage | File is "application/octet-stream" on upload from node.js cloud function 将 base64 字符串编码图像/字节图像作为图像传递到 Firebase ML Vision Flutter 中进行处理 - Passing a base64 string encoded image/ byte image as an image for processsing in Firebase ML Vision in Flutter 如何返回不在 base64 中的图像 - How to return image NOT in base64 当我上传图像 firebase 存储 getdownloadUrl() 将下载 url 放入 Firestore Collections 但未在 React JS 中设置 - When I upload a image firebase storage getdownloadUrl() put download url In Firestore Collections but not set it in React JS 我将图像上传到 firebase 存储,但在 firebase 存储中看不到图像 - I upload an image to firebase storage but i can't see image in firebase storage 如何使用 AWS Lambda [NodeJS] 将 base64 编码字符串作为图像上传到 S3 - How to upload a base64 encoding string as an image to S3 using AWS Lambda [NodeJS] 图片上传到Firebase storage failed on storage - Image upload to Firebase storage failed on storage 我正在尝试将图像上传到 firebase 存储并获取下载 url - I'm trying to upload an image to firebase storage and get the download url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM