Prajakta
Prajakta

Reputation: 11

Save image in local storage captured with cordova media capture plugin

I have added code in my ionic application using typescript to capture image. I have used cordova-media-capture plugin.

I am able to capture image, but when I go into my gallery I am not able to see that captured image.

I am having android Moto G4 mobile. Can anyone guide me on what could be the issue. Is it saving somewhere else or is I need to save it explicitly.

Upvotes: 0

Views: 1097

Answers (1)

pro_cheats
pro_cheats

Reputation: 1582

U can look into the array of MediaFile object in OnSuccess() function, describing each captured Image.

The MediaFile object has following properties -

  • name: The name of the file, without path information. (DOMString)
  • fullPath: The full path of the file, including the name. (DOMString)

  • type: The file's mime type (DOMString)

  • lastModifiedDate: The date and time when the file was last modified. (Date)

  • size: The size of the file, in bytes. (Number)

fullPath attribute will have the information you want.

Since you did not provide your code, I suppose your code is similar to this -

function imageCapture() {
   var options = {
      limit: 1
   };

   navigator.device.capture.captureImage(onSuccess, onError, options);

   function onSuccess(mediaFiles) {
      var i, path, len;

      for (i = 0, len = mediaFiles.length; i < len; i += 1) {
         path = mediaFiles[i].fullPath;

         console.log(mediaFiles); 
         //u can see the log message for details of the captured file

         navigator.notification.alert(mediaFiles); //alert the details
      }
   }

   function onError(error) {
      navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
   }    
}

Refer the Media Capture Documentation for more details.

Also see this tutorial (if required) for a working example.

Upvotes: 1

Related Questions