0

I want to get the file name and the native Path of the selected image from gallery. The below code works perfectly for Android But, gives null in IOS.

Titanium.Media.openPhotoGallery({
success : function(event) {
    selectedImage = event.media;
    //Ti.API.info("image : " + JSON.stringify(selectedImage));  --> Returns {}
    if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
        //Ti.API.info("selectedImage : " + JSON.stringify(selectedImage));    --> Returns {}
        //Ti.API.info("selectedImage : " + JSON.stringify(selectedImage.nativePath));  --> Returns null
        //Ti.API.info("selectedImage.file.name : " + JSON.stringify(selectedImage.file.name));  --> Throws error
    }
}
}); 

Is there any other way to get the fileName, ImageType and nativePath?

Thanks in Advance.

Fokke Zandbergen
  • 3,866
  • 1
  • 11
  • 28

1 Answers1

2

As you saw, you can't JSON serialize a blob to view all of its properties. And despite the documentation, it doesn't appear that you can get the native path on ios.

Titanium.Media.openPhotoGallery({
    success : function(e) {
        Ti.API.info ("Got image:");
        Ti.API.info ("  width:      " + e.media.width);
        Ti.API.info ("  height:     " + e.media.height);
        Ti.API.info ("  pixels:     " + e.media.size);
        Ti.API.info ("  bytes:      " + e.media.length);
        Ti.API.info ("  mimeType:   " + e.media.mimeType);
        Ti.API.info ("  nativePath: " + e.media.nativePath);
    }
}); 

Gives me

[INFO] Got image:
[INFO]   width:      3000
[INFO]   height:     2002
[INFO]   pixels:     6006000
[INFO]   bytes:      4752033
[INFO]   mimeType:   image/jpeg
[INFO]   nativePath: null

There is a file property associated with the image blob (it's definitely not null), but I can't access any properties of that file object. And as you can see, the nativePath is coming back as null.

That said, are you sure you need the native path? I've been able to get the image data, downsample it (using the ImageFactory module), and send it up to a server via HTTP, all without ever knowing the native path.

Jason Priebe
  • 479
  • 4
  • 11
  • `nativePath` (and some other Blob properties) are only available if the Blob comes from a file on disk. In the case of the photoGallery the Blob only exist in memory since you have no access to the original file in the photo gallery. – Fokke Zandbergen May 09 '16 at 08:24
  • Actually, I want to display imageName of selected image, is there any way to get the name? the flow I want is like, user selects the image from Gallery -> Image uploads to the server -> display the ImageName(filename) that has been uploaded in the app. – Kalpesh Bharambe May 20 '16 at 09:32