Home > Enterprise >  Why is it that when I upload a base64 image to firebase it shows in storage with extension applicati
Why is it that when I upload a base64 image to firebase it shows in storage with extension applicati

Time:10-08

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?

The Function handling the upload to firebase storage

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")
    })
}

CodePudding user response:

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. Also, try using uploadString() to upload base64 strings instead of uploadBytes()

Try specifing the contentType of your file as shown below:

uploadString(imageRef, files.base64.slice(23), 'base64', {
  contentType: 'image/png', // <-- replace with file's type
}).then(() => {
  alert('Image Uploaded')
})
  • Related