0

So I was building an app as an assignment from school which is supposed to upload pictures and forms to a server. On the broswer when using "ionic serve" the images upload just fine. But on the phone after installation after selecting the image you wish to upload it loads and loads forever and the image is not uploaded

function that takes in the image

async UploadImage(){
    const image= await Camera.getPhoto({
      quality: 90,
      allowEditing: false,
      resultType: CameraResultType.Base64,
      source: CameraSource.Photos,
    });

    console.log(image);

    if(image){
      const loading= await this.loadingController.create();
      await loading.present();

      let result= await this.formUpload.uploadImage(image);
      loading.dismiss();

      console.log(result[1])

      if(result[0]==false){
        const toaster= await this.toastController.create({
          position: 'bottom',
          message: "Image not uploaded",
          color: 'danger',
          duration: 3000,
        });
        toaster.present();
      }else{
        this.images.push(result[1])
      }
    }
  }

function that uploads the image and returns the url

async uploadImage(cameraFile: Photo){
        let now=new Date()
        const user=this.auth.currentUser;
        const path= `uploads/${user.uid}/formImage${now}.png`;
        const storageref= ref(this.fireStorage, path);

        try {
            await uploadString(storageref, cameraFile.base64String, 'base64');
            let imageUrl: string;
            imageUrl =await getDownloadURL (storageref);
            console.log(imageUrl)
            return [true, imageUrl];
        } catch (error) {
            return error
        }
    }

On the browser the image uploads perfectly well but on the phone just loads and loads and loads and nothing is done

2
  • Is it possible that the server has CORS restrictions? Take a look at this Github repository to see if it helps github.com/ionic-team/ionic-proxy-example Commented May 8, 2023 at 15:07
  • The thing is I used but Firebase. I recently added other functions to write to and read from and they work just not that one Commented May 9, 2023 at 16:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.