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:
- 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).
- 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.
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(); });
-
Will dig into it here