Getting Images to a Writable location

You must Login before you can answer or comment on any questions.

I'm writing an application where there are a few hundred merchants, and each one has a logo. For the existing merchants, I've put their logos in Resources/images/merchants - then when I need to serve up the image, I use a URL and that is all working fine.

The problem is, now there are new merchants that get added via an update process. I've learned that Titanium.Filesystem.getResourcesDirectory() may not be writable, and the application should not attempt to write to it. This means, for new merchants, my best bet is to use getApplicationDataDirectory(), but doing this as is would leave my images in 2 different directories, which wouldn't be good.

Possible Solution: When the app first starts, transfer all the merchant logos from getResourcesDirectory() to somewhere in getApplicationDataDirectory()?

Ideally, I would like to ship the app with the images in a location that is writable so that they don't need to be moved. Does such a location exist? Has anyone else tackled this same problem and have an elegant solution?

Thanks in advance...

2 Answers

Accepted Answer

I am on the same path: a content distributed with the app that can be replaced. As you state, at first run you can copy the content to the applicationDataDirectory. And this is what I do. You can also download it to that directory without having to include into your distribution

— answered 11 months ago by alessandro la rocca
answer permalink
5 Comments
  • A few hundred icons means a few hundred GET requests, and I'm trying to keep the initial data download as small and as fast as possible. However, I think copying over the icons is a decent solution.

    — commented 11 months ago by Timothy Powell

  • In my app I need to update a lot of contents too (jpg and mp3). I download them as single zip archive and then unzip into the applicationData

    — commented 11 months ago by alessandro la rocca

  • Hmm...I like :). Any chance you can show us some of boilerplate code for that? As far as retrieving the file, unpacking, and iterating through each file...?

    — commented 11 months ago by Timothy Powell

  • Show 2 more comments

Hi Timothy

The problem with copying the images from your resources folder to the ApplicationDataDirectory is that you then have duplicated the file space those images take up.

I would imagine you are adding the merchant information into a local database, with existing entries already being included and new ones being added.

I would consider adding a flag field to the merchant table which tells you where to find the image. This way in any loop you are running you can simply ask the recordset which of two location should you look and a simple if statement will resolve the problem.

This tiny change will more than be made up for in the extra file size needed to host a proportion of images twice, and would be better for your app users as well as your app takes up less space.

The flag field could be a simple integer; with 0 or 1 stored in it.

Your Answer

Think you can help? Login to answer this question!