Not allowed to load local resource: ionic 3 android

后端 未结 9 1558

I am using ionic 3 android build apk and trying to laod image from file:///storage/emulated/0/data/io.ionic.vdeovalet/cache/image.jpeg


         


        
相关标签:
9条回答
  • 2020-12-14 20:34
    let win: any = window; // hack ionic/angular compilator
    var myURL = win.Ionic.WebView.convertFileSrc(myURL);
    
    0 讨论(0)
  • 2020-12-14 20:43

    The only thing that worked for me was convertFileSrc()

    let win: any = window; let safeURL = win.Ionic.WebView.convertFileSrc(this.file.dataDirectory+'data/yourFile.png');

    Hope this helps

    0 讨论(0)
  • 2020-12-14 20:45

    Try this:

    const options: CameraOptions = {
        quality: 10
        , destinationType: this.camera.DestinationType.DATA_URL
        , mediaType: this.camera.MediaType.PICTURE
        // Optional , correctOrientation: true
        , sourceType: sourceType == 0 ? this.camera.PictureSourceType.CAMERA : this.camera.PictureSourceType.PHOTOLIBRARY
        // Optional , saveToPhotoAlbum: true
    };
    
    this.camera.getPicture(options).then(imageBase64 => {
        let txtForImage = `data:image/jpeg;base64,` + imageBase64;
        this.imageToLoad = txtForImage;
    })
    .catch(error => {
        alert("Error: " + error);
        console.error(error);
    });
    
    0 讨论(0)
提交回复
热议问题