I'm trying to update the version 8 code to version 9, but the image that is uploaded yields Error loading preview ...
Here is the code:
async storeImage(img: { uri: string; base64: string }, userId: string) {
try {
let imageUrl = null;
const imageName = img.uri.substring(img.uri.length - 40);
const imageRef = ref(this.storage, `profile-images/${userId}/${imageName}`);
uploadString(imageRef, img.base64, 'base64', { contentType: "image/jpg" }).then((snapshot) => {
console.log("image stored", snapshot);
})
getDownloadURL(ref(this.storage, `profile-images/${userId}/${imageName}`))
.then(url => {
const xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = (event) => {
const blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
console.log('getDownloadURL', url);
imageUrl = url;
})
return imageUrl
} catch (error) {
console.log(error);
}
}
}
The uri string is the address on the device, the base64 is
/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAyKADAAQAAAABAAAAhAAAAAD/7QA4UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAA4QklNBCUAAAAAABDUHYzZjwCyBOmACZ...
This is the url from the firebase storage preview.
This is the downloaded url, which should be the same as the above.
I tried also in uploadString to use base64url but nothing.
Any kind of help would be appreciated.
Thanks in advance.