簡體   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