3

i have been using this code to store an image from imageviewer to device memory.

blobObj = imageView.toImage(); 

var f = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'img.png');
f.write(blobObj);
Titanium.Media.saveToPhotoGallery(f,{
success: function(e) {
    Titanium.UI.createAlertDialog({
        title:'Photo Gallery',
        message:'Check your photo gallery for image '
    }).show();      
},
error: function(e) {
    Titanium.UI.createAlertDialog({
        title:'Error saving',
        message:e.error
    }).show();
}
});

What i want is to get the native path of currently saved image from memory

Thankyou

h_h
  • 1,201
  • 4
  • 28
  • 47

2 Answers2

2

Dear Please see the below example to get native path where the image is stored in titanium file system

// Native path
var filename = "image.png";

// Create the file in the application directory       
bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);

// Write the image to the new file (image created from camera)
bgImage.write(image);

// bgImage.nativePath, it is alos native path, but you can get through below code.
nativePath = Titanium.Filesystem.applicationDataDirectory + Ti.Filesystem.separator + filename;
alert(nativePath);

Hopefully, it will for you. It is working on my side.

Prasad Khode
  • 6,602
  • 11
  • 44
  • 59
Ali Sher Kashif
  • 2,133
  • 2
  • 11
  • 13
1

As this only works on iOS (see docs) i guess you are on iOS Platform.

If you create an image via blobObj = imageView.toImage(); you will receive a Titanium.Blob object. This object can be persisted somewhere in your app, it can also be temporarily available in memory.

If you store this image to the media gallery you won't get a file path to this image as this is not allowed by the iOS platform. So finally: What you want to do is not possible.

But: You can store the image yourself persistently within your app's data storage (using Ti.Filesystem).

To retrieve a file path for the temp object use f.nativePath or f.resolve().

Don't forget: You'll never get a path to the media gallery's photos. Even if you load an image from there you'll get a temporary path.

mr.VVoo
  • 2,265
  • 20
  • 30