ACCESS LOCAL FILE PATH IN IONIC 4

we mainly need three things required to access the local file path in ionic 4.

First, we need an ionic camera plugin 

second,  DomSanitizer on importing “platform-browser” 

third, Webview on. importing “ionic-webview”

 Let's continue on the codding part. Get indepth use of ionic camera plugin , domsanitizer and ionic-webview.

We need to install an ionic camera plugin. So simply Run given below command.
ionic cordova plugin add cordova-plugin-camera
npm install @ionic-native/camera
After Installation , Add it on “app.module.ts” inside the providers section. Now you are able to use the ionic camera plugin. Now go to the page where you write the action of the camera plugin. just Assume,  I will take tab1.page.html . Now you can go to tab1.page.ts

knowledge point of view

Camera option having so many parameters, Here we explain important one.
“quality”: In quality, we can set the quality of images and we can achieve the compress of an image. If you minimize the quality of the image.

“destinationType”: it gives the type of local file path to be used. Mainly it takes three values at a time. That is

i. DATA.URL (it gives Base 64 file path, As my recommendation doesn’t use access to bigger file size content. it might be the app would be crashed.)
ii.FILE_URI ( it gives the full path of the file. )
iii.NATIVE_URI ( Return native URI (eg. asset-library://… for iOS)

“mediaType”: Mainly it takes three values at a time.
i. “ALLMEDIA” : ( Returns images and videos both of them at a time)
ii. “PICTURE” : (Returns images only)
iii. “VIDEO” : (Retuns video only)

“sourceType” It’s three values at a time to use the handle. Either use camera or Gallery.
i. camera ( Return open the camera mode )
ii. PHOTOLIBRARY ( Return picture library , It only works on android, not for ios)
iii.SAVEDPHOTOALBUM ( Return picture library. Work on both devices. One thing note it’s also related to media type.
If you select mediaType is “PICTURE”. So SAVEDPHOTOALBUM gives images only.
If you select mediaType is “ALLMEDIA”. So SAVEDPHOTOALBUM gives images and videos.
If you select mediaType is “VIDEO”. So SAVEDPHOTOALBUM gives videos only.

Leave a Reply