EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

Upload Image directly from camera plugin to firebase storage #1668

Closed felicks closed 3 years ago

felicks commented 3 years ago

Unfortunately, I can't find a solution with the offered documentation. Can you help me with this?
Im not sure how to upload the file to firebase...

public takePicture() {
      camera.takePicture()
      .then((imageAsset) => {
        source.fromAsset(imageAsset)
        .then((imageSource: ImageSource) => {
            const folderPath: string = knownFolders.documents().path;
            const fileName: string = Date.now() + ".jpg";
            const filePath: string = path.join(folderPath, fileName);
            const saved: boolean = imageSource.saveToFile(filePath, "jpg");

            if (saved) {
                console.log("Saved: " + filePath);
                console.log("Image saved successfully!");
                this.uploadToFirebase(filePath, fileName)
            }
        });
      }).catch((err) => {
          console.log("Error -> " + err.message);
    });
    }

    uploadToFirebase(path, name) {
      firebase.storage.uploadImage(path,name).then((data) => {
        console.log("Uploaded " + name)
      }); 
    }
EddyVerbruggen commented 3 years ago

I'm using it here in a project, hope that helps: https://github.com/EddyVerbruggen/footplr/blob/71c4f0d519cd3bea51a069f389e1a53d9711dd76/app/pages/home/components/profile/Profile.vue#L210-L247

felicks commented 3 years ago

Thanks a lot. I'm using Angular though. I hope I can make work with your code

felicks commented 3 years ago

@EddyVerbruggen Thanks for your help, it's working now!

Edit: solved the issue