0

So I have the following which works real nice as is:

 button.addEventListener("click", function(e){
    Titanium.Media.showCamera({
        success:function(e){
            if(e.mediaType === Titanium.Media.MEDIA_TYPE_PHOTO){
                var imageView = Titanium.UI.createImageView({
                    image: e.media,
                    width: 'auto',
                    height: 'auto',
                    top: 50,
                    zIndex: 1
                });
                win.add(imageView);
            } else {
                alert("Only Photos aloud");
            }
        },
        error:function(e){
            alert("There was an error");
        },
        cancel:function(e){
            alert("The event was cancelled");
        },
        allowEditing: true,
        saveToPhotoGallery: true,
        mediaTypes:[Titanium.Media.MEDIA_TYPE_PHOTO,Titanium.Media.MEDIA_TYPE_VIDEO],
        videoQuality:Titanium.Media.QUALITY_HIGH
    }); 
});

saveToPhotoGallery just adds the taken photo to the default gallery in the iOS Photos App. I need to add the photo to a specific folder in the iOS Photos App though. Has anyone an idea how I could do this from with Titanium ? I have been searching the intewebs but have not found anything on how to add a taken photo to a specific folder.

Thank for the help guys

Chris

Chris
  • 419
  • 2
  • 16

1 Answers1

0

But, let me specify that the file can be save in the Application Directory only in IOS but in android you can save it in the externalStorage. You can have look at the documentation through the below link :

https://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage

You can easily save the file to your folder using the following code :

if (OS_ANDROID) {
    var f12 = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory);
} else {
    var f12 = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
}

var galleryImg = e.media;
var fileToSave = null;
var fileName = 'IMG' + todayDate + "HB" + Ti.App.Properties.getInt('imgCounter') + '.jpg';
if (OS_ANDROID) {
    fileToSave = Titanium.Filesystem.getFile(f12.resolve(), fileName);
} else {
    fileToSave = Titanium.Filesystem.getFile(f12.resolve(), fileName);
}
fileToSave.write(galleryImg);

If you want to create a subDirectory then use the following code :

var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mysubdir');
dir.createDirectory(); // this creates the directory

But, let me specify that the file can be save in the Application Directory only in IOS but in android you can save it in the externalStorage. You can have look at the documentation through the below link :

https://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage

EDIT

You Could do it this way :

// get the TiBlob 
var blob = img_view.toImage();

// try to save the image the image
Ti.Media.saveToPhotoGallery(blob,{
    success: function(e){
        if (callback == undefined) {
           alert('Saved image to gallery');
        } else {
           callback();
        }
    },
    error: function(e){
        alert("Error saving the image");
    }
});

Good Luck, Cheers

Community
  • 1
  • 1
A. A. Sebastian
  • 540
  • 1
  • 7
  • 19
  • I was actually hoping to add the photo to the native iOS Photos app. This seems to add the Photo to an app internal file storage system am I right? Is there a way to add the Photo to a folder in the Photos App ? – Chris Mar 16 '17 at 09:00
  • ! My bad ! I had the wrong code snippet in the question...! I actually am using the showCamera function which opens the camera and not the openPhotoGallery function. Sorry. So I updated the question. – Chris Mar 16 '17 at 09:29
  • @Chris : I had mentioned this earlier in the same answer, that it will not be possible in the iOS. I have update the question, highlighting the same point. Please have a look. – A. A. Sebastian Mar 16 '17 at 09:43
  • Ah yes thank you very much. I was nearly sure there must be a way to do this. I will then probably opt for storing the pic in the filesystem only. – Chris Mar 16 '17 at 09:58