Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Save Image Blob

Tags:

titanium

I am trying to save an image from the photo gallery to local storage so that I can load the image up across application sessions. Once the user is done selecting the image, the following logic is executed. On the simulator I see the error message is written out to the log. Even though I am seeing the error message I think the image is still saved in the simulato because when I restart the application I am able to load the saved image. When I run this on the device though, I still get the error message you see in the code below and the default background is loaded which indicates the write was not successful.

Can anyone see what I am doing wrong and why the image won't save successfully?

var image = i.media.imageAsResized(width, height);
backgroundImage.image = image;      
function SaveBackgroundImage(image)
        {
            var file = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,W.CUSTOM_BACKGROUND);
            if(file.write(image, false))
            {
                W.analytics.remoteLog('Success Saving Background Image');
            }
            else
            {
                W.analytics.remoteLog('Error Saving Background Image');
            }
            file = null;            
        }
like image 964
Kevin Avatar asked Dec 29 '25 03:12

Kevin


1 Answers

Try this Code:

var parent = Titanium.Filesystem.getApplicationDataDirectory();
var f = Titanium.Filesystem.getFile(parent, 'image_name.png');
f.write(image);
Ti.API.info(f.nativePath); // it will return the native path of image

In your code i thing you are not giving the type of the image (png/jpeg) thats why your getting error.

like image 159
Hasnain Avatar answered Jan 02 '26 15:01

Hasnain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!