Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Mission: You will the image that the user selected from the camera or gallery to the filesystem and associate it with the fugitive's model for later retrieval.

Specification: In this lab, you will modify the app created in the preceding lab. You will save the file to the filesystem and update the model so the image can be displayed the next time the user shows the details for a fugitive.

To successfully complete this lab, you must develop an application that meets the following description:

  • Save the image's binary data to a file in the application data directory with a name of photo#.png, where # is the fugitive's ID.
  • Set the model's url property equal to the file's native path.
  1. Download the starting code for this lab 09_filesystem and unzip the files. Import the project into Titanium Studio. Update the tiapp.xml, if necessary (e.g. to set an appropriate SDK version or build target for your environment).
  2. In the FugitiveDetail.js controller, update the success callback in the photo button's event listener.
  3. Create a file named photo#.png, where # is the model's ID, in the application data directory and write the media to the file system.
  4. Create a variable named fugitiveModel that points to the value. This will represent the current model. Set its url property equal to your file's native path. Save the model. Fetch the records from the collection.
  5. Save all the files. Build your app for the iOS simulator or Android emulator. Correct any problems that exist.

Your finished app should match the screen shot above. Now when you select an image from the camera or gallery, it should be saved and available the next time you open the details screen for that fugitive.


In this lab, you extended the supplied example app to save the image associated with a fugitive.


API docs: Ti.Filesystem!/api/Titanium.Filesystem
API docs: Ti.File!/api/Titanium.Filesystem.File
Starting point for this lab: 09 09_filesystem
Finished code for lab 08 Multimedia: 08_multimedia