Upload image in local storage phone using Ionic 3

Nota ni bakal dikemaskini~

Gunakan plugin
- camera
- file
- webview
- domsanitizer


const optionsCameraOptions = {
              quality: 70,
              destinationType: this.camera.DestinationType.FILE_URI,
              encodingType: this.camera.EncodingType.JPEG,
              sourceType : this.camera.PictureSourceType.CAMERA,
              mediaType: this.camera.MediaType.PICTURE,
              allowEdit : true,
              targetWidth: 500,
              targetHeight: 500,
              saveToPhotoAlbum: true
            }

            const tempImage = this.camera.getPicture(options).then((imageData=> {

              var tempFilename = imageData.substr(imageData.lastIndexOf('/') + 1);
              tempFilename = tempFilename.substr(0tempFilename.lastIndexOf("?"));
              var tempBaseFilesystemPath = imageData.substr(0imageData.lastIndexOf('/') + 1);
              var newBaseFilesystemPath = this.file.dataDirectory;

              this.file.copyFile(tempBaseFilesystemPathtempFilenamenewBaseFilesystemPathtempFilename);
              var storedPhoto = newBaseFilesystemPath + tempFilename;
              
              var resolvedImg = this.win.Ionic.WebView.convertFileSrc(storedPhoto);
              this.photo = this.sanitizer.bypassSecurityTrustStyle('url(' + resolvedImg + ')');
                
              this.global.sendNotification('Success');
            }, (err=> {
              this.global.sendNotification('Failed');
            });


Sumber rujukan : 

Storing Photos with the Cordova Camera and File Plugins


Not allowed to load local resource: ionic 3 android

WARNING: sanitizing unsafe style value url


Ulasan

Catatan popular daripada blog ini

SISTEM PENGOPERASIAN KOMPUTER (OS)

APA ITU ASCII (AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE) ?

APA ITU EBCDIC (EXTANDENT BINARY CODEC DECIMAL INTERCHANGE CODE) ?

JENIS-JENIS SISTEM PENGOPERASIAN KOMPUTER

Router CP2001/RS980+ dan Cara config