![](/img/trans.png)
[英]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.