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 typeapplication/octet-stream
. Also, try usinguploadString()
to uploadbase64
strings instead ofuploadBytes()
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')
})