I use CameraPreview to create an image (b64). I can use
img = 'data:image/jpeg;base64,' + imageData;
const pictures = storage().ref('pictures/initTest');
pictures.putString(img, 'data_url');
to succesfully upload the image to firebase.
Now I want to store the image to a certain folder:
DATA_DIR = this.file.externalDataDirectory;
private writeFile(img, photo_path, photo_name) {
const bytes: string = atob(img);
const byteNumbers = new Array(bytes.length);
for (let i = 0; i < bytes.length; i++) {
byteNumbers[i] = bytes.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
const blob: Blob = new Blob([byteArray], { type: 'image/jpg' });
this.file.writeFile(photo_path, photo_name, blob);
}
This works. I find my image in the file explorer.
Now all I want is to upload this image to firebase… But no matter what I do, it does not work. I tried to convert it back to b64 - no success. I tried to upload it to firebase using:
const pictures = storage().ref('pictures/initTest');
pictures.put(path);
where path is exactly the path + filename where i have stored my image - no succes…
It must be sooooo simple. But how can I upload that image to firebase??? Please help, I feel so stupid as it probably is so easy…
I am quite new to Ionic and ABSOLUTELY confused…