openPhotoGallery and Titanium.Filesystem.getFile : Bug ?
Hey,
I try to select a picture with openPhotoGallery, and write with Titanium.Filesystem.getFile, after that i want to change the background of the windows…. It's work, but just the first time !
I check in / iphone simulator / user / …. / Documents /test.jpg at each change the image in the directory is good (!!), but not in the application (is always the first selected) ! As if he had a cache issue ….The background reload, but always with the same image (the first!).
When I reload the app, the image is the last selected (this confirm when I write with Filesystem it's work fine).
So…. It's very important for my app, please somebody can help me?
I use Titanium Developer 1.0 / SDK 1.0 and Iphone SDK : 3.1.3
Thank you
var win = Titanium.UI.currentWindow;
var backgd = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,"test.jpg");
if(backgd.exists()){win.backgroundImage = backgd.nativePath;}
var add = Titanium.UI.createButton({systemButton:Titanium.UI.iPhone.SystemButton.ADD});
win.rightNavButton = add;
add.addEventListener('click',function()
{
Titanium.Media.openPhotoGallery(
{
success:function(event)
{
var cropRect = event.cropRect;
var image = event.media;
var thumbnail = event.thumbnail;
var BackgroundFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,"test.jpg");
BackgroundFile.write(image);
//DEBUG
Ti.API.info('file = ' + BackgroundFile);
var contents = BackgroundFile.read();
Ti.API.info("contents blob object = "+contents);
Ti.API.info('contents = ' + contents.text);
Ti.API.info('mime type = ' + contents.mimeType);
Ti.API.info('nativePath = ' + BackgroundFile.nativePath);
Ti.API.info('exists = ' + BackgroundFile.exists());
Ti.API.info('size = ' + BackgroundFile.size);
Ti.API.info('readonly = ' + BackgroundFile.readonly);
Ti.API.info('symbolicLink = ' + BackgroundFile.symbolicLink);
Ti.API.info('executable = ' + BackgroundFile.executable);
Ti.API.info('hidden = ' + BackgroundFile.hidden);
Ti.API.info('writable = ' + BackgroundFile.writable);
Ti.API.info('name = ' + BackgroundFile.name);
Ti.API.info('extension = ' + BackgroundFile.extension());
Ti.API.info('resolve = ' + BackgroundFile.resolve());
win.backgroundImage = null;
win.backgroundImage = BackgroundFile.nativePath;
Titanium.API.info('PHOTO GALLERY SUCCESS cropRect.x ' + cropRect.x + ' cropRect.y ' + cropRect.y + ' cropRect.height ' + cropRect.height + ' cropRect.width ' + cropRect.width);
},
cancel:function()
{
},
error:function(error)
{
Titanium.UI.createAlertDialog({title:'Erreur', message:'...'}).show();
},
//allowImageEditing:true,
//mediaTypes: Titanium.Media.MEDIA_TYPE_PHOTO
});
});
4 Answers
-
Before you write the test.jpg file, you should write a test to see if it 'exists' first, then delete it if it does.
Your code is probably not able to overwrite the first one.
hope this helps,
Kosso -
How do I delete test.jpg?
The second picture selected is saved in the cache of the application (see
/ iphone simulator / user / …. / Documents /test.jpg, after selecting the image, we can ensure that it's good)I had a reply on the old forum here :
http://support.appcelerator.net/discussions/support/2368-10-titaniumfilesystemgetfile-bugIf someone has an alternative to offer me ….
Thank you.
It's essential for my application, I can't finish because of this :( -
You can use this code for this.
var image = event,media; var filename = new Date().getTime() + "-app.jpg"; bgImage = Titanium.Filesystem.getFile(desigantionFile, filename); bgImage.write(image);
-
Simply do a
bgImage.deleteFile();
… at the end of your code…