Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Photo upload related issue

I am developing a photo upload form for Android platform. In this form I can attach an existing of take new photo and attach it. In this two scenarios, following happens:

  1. When a take picture and click "Add" and send the form, following pictures are created:
  • picture in "Images" folder with the original size (2010-07-27 22.15.25.jpg).
  • picture in "DCIM/Camera" folder with small size (tia49516.jpg).
  • picture on the root of the card with small size (tixhr49517jpeg).
  1. When I attach an existing photo and send the form, following pictures are created:
  • picture in "Images" folder with the original size (2010-07-27 22.23.40.jpg).
  • picture on the root of the card with small size (tixhr49519jpeg).

Questions:

How do I have more control on the saved pictures?

How do I disable or delete the pictures saved on the card that are sent (tixhr)?

How do I disable saving pictures to photo gallery (saveToPhotoGallery: false does not work)?

p.s. My Titanium version built is about 10 days old.

— asked July 27th 2010 by Dalibor Nasevic
  • android
  • photo
0 Comments

2 Answers

  • I found a solution by Chris King at http://developer.appcelerator.com/question/114181/unable-to-delete-temporary-files

    Here is my modified version of his code.

    I added a part to also clean out the tia images that are left laying around in the sdcard/dcim/Camera/Your Apps Folder/ after your app takes pictures with the camera.

    Im guessing since I'm a newbie, my code could have been somehow better, but hey, it works! :)

    I have the function running when the app closes, which it does when the main and final window is closed with the Android back button.

    function cleanupTitaniumMesses() {
        if (Ti.Filesystem.isExternalStoragePresent) {
            try {
                var n = Ti.UI.createNotification({message:'Your App Name is cleaning up tixhr files...'});
                n.duration = Ti.UI.NOTIFICATION_DURATION_SHORT;
                n.show();
    
                var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory); 
                var fileList = dir.getParent().getDirectoryListing();
                var l = fileList.length;
    
                for(var i=0; i<l; i++) {
    
                    var file2 = fileList[i];
                    var fileName = file2.toString();
                    fileName2 = fileName.substr(fileName.lastIndexOf("/") + 1);
    
                    if (fileName2.substr(0,5) === 'tixhr') {
                        var path = dir.getParent().nativePath;
                        var file = Titanium.Filesystem.getFile(path+'/'+file2);
                        file.deleteFile();
                    }
                }
    
                var n = Ti.UI.createNotification({message:'Your App Name is cleaning up tia image files...'});
                n.duration = Ti.UI.NOTIFICATION_DURATION_SHORT;
                n.show();
    
                var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory); 
                var dir2 = dir.getParent().nativePath.toString() + '/dcim/Camera/Your Apps Folder/';
                var dir3 = Titanium.Filesystem.getFile(dir2); 
                var fileList = dir3.getDirectoryListing();
                var l = fileList.length;
    
                for(var i=0; i<l; i++) {
                    var file2 = fileList[i];
                    var fileName = file2.toString();
                    fileName2 = fileName.substr(fileName.lastIndexOf("/") + 1);
                    if (fileName2.substr(0,3) === 'tia') {
                        var path = dir3.nativePath;
                        var file = Titanium.Filesystem.getFile(path+'/'+file2);
                        file.deleteFile();
                    }
                }
    
                dir3.deleteDirectory();
            }
    
            catch(e) {
                var n = Ti.UI.createNotification({message:'Non-critical error purging stray tixhr files from SD Card root. You will want to periodically delete all files that start with the name tixhr from the root of your SD Card.\n\n' + e.message});
                n.duration = Ti.UI.NOTIFICATION_DURATION_LONG;
                n.show();
            }
    
        } 
    }
    
    winMain.addEventListener('android:back', function(e) {
        cleanupTitaniumMesses();
        winMain.close();            
    });
    
    — answered July 16th 2011 by Ken Rucker
    permalink
    0 Comments
  • Will dig into it here

    — answered June 25th 2012 by Eduardo Gomez
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.