Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 37 ยท Projects and Practice

Project: Photo Journal with Camera and Location

Build a photo journal in Ionic: capture photos, save files with a metadata index, tag entries with location, group by day and handle permissions and deletion safely.

The photo journal combines the native features of this course: Camera, Filesystem, Geolocation and Preferences or SQLite. A user takes a photo, the app saves the image file, records where and when it was taken and shows entries grouped by day. It is a good practice project because it forces you to think about files, permissions, cleanup and failure.

You should have read Camera and Filesystem and Geolocation, Device and Network first.

What the app does

  1. A "+" button opens the camera (or gallery).
  2. The photo is saved as a file in Directory.Data under journal/.
  3. An entry record { id, file, caption, takenAt, place } is saved in the index.
  4. The home page shows entries grouped by date, newest first.
  5. Deleting an entry deletes the file and the record.
  6. If location is denied, the entry is simply saved without a place.
sequenceDiagram
    participant U as User
    participant P as JournalPage
    participant C as Camera
    participant F as Filesystem
    participant G as Geolocation
    participant I as Index store
    U->>P: tap +
    P->>C: getPhoto
    C-->>P: webPath
    P->>F: writeFile journal/id.jpeg
    P->>G: getCurrentPosition (optional)
    G-->>P: coords or error
    P->>I: save entry
    P-->>U: new entry on top

The photo and the location are independent: a failure of the second must not lose the first.

The data

Keep the index small and the files separate. Store file names, not base64 strings, in the index. The index is a list of entries saved with Preferences; if you expect thousands, use SQLite.

TypeScript
export interface JournalEntry {
  id: string;
  file: string;                  // 'journal/3f2a.jpeg' relative to Directory.Data
  caption: string;
  takenAt: number;               // epoch ms
  place?: { lat: number; lon: number; accuracy: number };
}

The capture flow

The important design is the order and the failure handling: write the file first, then write the index, and clean up if the second step fails. Otherwise you leave orphan files that waste space.

JS Capture flow with rollback

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Grouping by day

The home page shows a section per date. Group entries by the local date, not UTC, or a photo taken at 11 pm will appear on the next day for users far from Greenwich. Use Intl.DateTimeFormat with the user's locale for headings.

JS Group entries by local day

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The same moments fall on different days in different time zones, which is why the grouping must use the device's time zone.

The page

The Ionic template for the list is a loop over groups with ion-item-divider headings and ion-img thumbnails. Because images are files, convert each URI before binding:

TypeScript
async function toSrc(file: string): Promise<string> {
  const { uri } = await Filesystem.getUri({ path: file, directory: Directory.Data });
  return Capacitor.convertFileSrc(uri);
}

Resolve sources lazily (as items scroll into view) to keep the first render quick, as described in Performance and Lazy Loading. Make a smaller thumbnail at capture time (for example 400 px wide) and use it in the list; open the full image only on the detail page.

Edge cases to handle

  • Permission denied for the camera: offer the gallery picker.
  • User cancels the camera: getPhoto throws; do not show an error toast, just return.
  • Low storage: catch write errors and explain.
  • Deleted files: a user may clear app data or the OS may remove cache; if readFile fails for an index entry, show a placeholder and offer to remove the record.
  • Privacy: photos with location are sensitive. Say so in your privacy policy and give an option to turn location off.
  • Backups: decide whether the folder should be excluded from device backups.

Stretch goals

  1. Add a map or a "distance from here" label using the haversine function from the geolocation lesson.
  2. Export a day as a share sheet with captions.
  3. Add search by caption and a filter for entries with a place.
  4. Sync the index (not the images) to a server using the outbox pattern.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why write the photo file before the index entry?

    If the file exists first, a failure leaves at worst an orphan file you can clean up, not a broken record.
  2. 2. What should happen when location permission is denied while saving?

    Location is optional metadata, so the photo must not be lost.
  3. 3. Why group by local date instead of UTC?

    A day is a local concept; UTC grouping can move entries across midnight.
  4. 4. Where should the full list of entries store images?

    Base64 bloats the index and slows every load.

Summary

  • Keep images as files and metadata in a small index.
  • Order operations so that a failure leaves no broken records; roll back orphans.
  • Treat location as optional and permissions as something a user may refuse.
  • Group by the device's local day and use thumbnails for list performance.
  • Handle missing files, low space and privacy.

Next: Project: Trail Weather and Nearby Places