Skip to main content

Imports and metadata

This page follows a photo from the moment Lifer sees it to its place in the library, and lists exactly which metadata Lifer reads from files and which it writes back. Paths are relative to the repository root. For what users see, see Importing photos and Library folders.

Every import path ends the same way: the original file is filed into a species folder (or left where it is, if linked), three WebP previews are made under APP_DATA_DIR, a captures_all row records the file's hash and EXIF fields, and Lifer's species and rating tags are written back to the file in the background, but only to files it manages.

Import paths​

Upload from the web app or desktop app​

Two requests, so the user can review before anything is saved:

  1. POST /api/uploads/inspect (apps/api/src/uploads/inspect.ts) reads EXIF, keywords and cull marks, checks for duplicates and suggests species. It writes no database rows. A multipart file is kept in a staging folder and returned as a stagedId, so the import doesn't upload it again. Each photo checked this way also gets its previews and default card crop made in the background (apps/api/src/uploads/preparedAhead.ts), which the import reuses. That work runs only while no photo is being checked or imported, two at a time, and an import never waits behind it: a photo whose work hasn't started is dropped from the queue and the import makes its own previews.
  2. POST /api/uploads (apps/api/src/uploads/photo.ts) imports. Its mode is store (the default: file the file into the library) or link (leave it where it is, unmanaged; the path must pass the path allowlist).

POST /api/uploads/raw takes many RAW files at once (two in parallel), and POST /api/uploads/video takes MP4, MOV, AVCHD (MTS, M2TS), MXF, AVI, MKV and 3GP, by extension, or by MIME type when the file has no name.

The bytes arrive one of three ways (apps/api/src/uploads/uploadSource.ts): a multipart part streamed to a temp file, a stagedId from inspect, or the id of a finished tus upload. The web app always uses tus (apps/web/src/lib/tusUpload.ts): chunks start at 8 MiB and halve, down to 256 KiB, when a proxy refuses one as too large, which is why Lifer works behind proxies with default body limits. The server side (apps/api/src/lib/tusUploads.ts, built on @tus/server and @tus/file-store) hashes each chunk as it's written, ties each upload to its user, and re-hashes the file when an import claims it. Uploads idle for two hours are swept by lib/maintenance.ts.

Received files land in an upload work folder (apps/api/src/lib/uploadWorkDir.ts): LIFER_UPLOAD_WORK_DIR if set, otherwise APP_DATA_DIR/uploads when that's on the same drive as the library, otherwise .lifer-uploads inside the library. Being on the same drive makes filing a file a rename instead of a copy.

Trip folders​

A trip points at a folder of photos, typically a card dump (apps/api/src/trips/). Scanning (scan.ts) lists photos whose SHA-256 isn't already a capture, skipping the trip's destination folder and dot files, and reads their cull marks. Importing (import.ts, run four files at a time by jobs.ts) copies each chosen photo, and its RAW twin, into <trip destination>/<taxon>/<species>/Adjusted/ and RAW/. The source folder is never modified. A failed import deletes the copies it made. Each file path is checked to stay inside the trip folder after symlinks are resolved (resolveWithinTripFolder).

Checklists from eBird​

POST /api/imports/ebird-csv (apps/api/src/imports/routes.ts) reads an eBird "My eBird Data" export. It needs only a "Scientific Name" column, matches names exactly against species.scientific_name, and marks each match seen in user_species with ON CONFLICT DO NOTHING, so a collected species is never downgraded. It returns the matched, already-seen and unmatched counts, the unmatched names, and the ids of the species it newly marked. POST /api/imports/ebird-csv/undo takes those ids back and clears only rows still plain seen, so nothing photographed since is touched and no schema change is needed to remember the import. No photos are involved, and Lifer never contacts eBird. The CSV parser is minimal: it doesn't handle commas inside quoted fields.

There's no other life-list import. iNaturalist is the other direction: Lifer sends selected photos to iNaturalist as observations (apps/api/src/inaturalist/); it doesn't import from it.

Reimporting a library from disk​

POST /api/library/reimport (apps/api/src/library/routes.ts, reimport.ts) rebuilds captures from files already on disk: the library, a registered drive, or an allowed folder. It's the recovery path when the database is lost; see State and sync. Species come from keywords Lifer wrote earlier, and from the file and folder names. Anything ambiguous is listed for the user to decide, never guessed. Photos a culling app rejected are skipped by default, or recovered hidden or as usual (the cullMarks field, as for uploads; Cull marks), and the photo tags Lifer wrote into a file come back with it.

RAW and JPEG pairing​

RAW extensions are listed in packages/core/src/uploads/formats.ts (.cr2 .cr3 .nef .nrw .arw .raf .rw2 .orf .dng .pef .srw, and .tif/.tiff only when the file holds sensor data). Lifer doesn't develop RAW files; it shows the JPEG preview embedded in them (PreviewImage, then JpgFromRaw, then ThumbnailImage, in apps/api/src/uploads/exif.ts).

A RAW and a JPEG are one capture with two originals rows (kind = 'raw' and 'jpeg'). When a RAW arrives (findRawRelatedCaptures in apps/api/src/uploads/rawMatching.ts), Lifer looks for a capture with no RAW yet:

  1. Same file name stem, ignoring a -2 style suffix, and a capture time within one second. It counts only if exactly one capture matches.
  2. Otherwise an EXIF fingerprint: strict is SHA-256 of capture time, sub-seconds, camera model and serial number; loose drops the sub-seconds and serial (exif.ts). Strict first, then loose.

One match links. Several matches are a collision and nothing links. No match: in a folder import the RAW isn't kept; picked for one species, it's filed into that species' RAW folder as an unlinked original (capture_id NULL, species_id set) that a later JPEG can claim; imported as the main file, it becomes its own capture shown through its embedded preview (apps/api/src/uploads/raw.ts).

A JPEG that arrives after its RAW claims the waiting RAW the same way, by stem and time, then by fingerprint (photo.ts). Trip imports pair by stem only, case-insensitively, preferring a RAW in the photo's own folder (trips/import.ts).

Photo versions​

Edits and exports of one photographed moment (_M8A6162-2.jpg, _M8A6162-6.jpg, a denoised DNG) are grouped so the moment counts once. Every file is still imported as its own capture; once imports go quiet, a background pass (apps/api/src/uploads/versionGrouping.ts) reads each new file's role and links versions. A version's capture is hidden behind its group's capture (capture_versions), so the life list, species counts and Home count it once, and a split brings it back exactly as it was.

Each originals row gets a role: original (the camera file), edit (a DNG, TIFF or PSD saved by an editor) or export (any other derived file). A file is derived when its XMP lineage points elsewhere, its name carries an editor suffix (-2, -Edit, -Enhanced-NR, -Pano, -HDR, a size such as _10x27), or its Software is an editor. document_id is its OriginalDocumentID, else DerivedFromDocumentID, else its own DocumentID.

The rules, strongest first. Only the first two link on their own:

  1. Same document (document_id evidence): files sharing a document_id.
  2. Same shutter press and name (time_serial_suffix): the same strict fingerprint, with sub-seconds and a serial number present, and stems that match once suffixes are removed. Two files whose document IDs differ never link this way.
  3. Same shutter press only (suggested): offered in the review after an import, never linked until a person confirms.

Several candidate groups is ambiguous and nothing links. Size and dimensions are never a signal, since crops and panoramas differ. A split or dismissed suggestion stays dismissed, so the rules never link it again. A group shows its newest edit, else its camera original, unless the user picks another file ("Use as the photo", which swaps the two captures' photo rows).

EXIF, GPS and time​

Lifer reads metadata with ExifTool through exiftool-vendored (apps/api/src/uploads/exif.ts), one ExifTool process per CPU core. It reads DateTimeOriginal, GPS latitude and longitude, camera model, lens, focal length, aperture, shutter speed, ISO, rating, and keywords (Keywords, Subject, TagsList, HierarchicalSubject, keeping only the last level of a hierarchy).

Capture time is the hard part, because most cameras record local wall-clock time without a zone:

  • If ExifTool gives the time a zone (from OffsetTimeOriginal, or one exiftool-vendored infers from other timestamps or GPS with its default options), Lifer stores that instant.
  • Otherwise it reads the wall-clock time as UTC, so the stored value doesn't depend on the server's own time zone.
  • The camera's wall-clock time is kept separately and used for file names and the year folder, so a photo taken at 23:30 on 31 December stays in that year whatever zone the server is in. Uploads, trip imports, reimport's "organize" and Reorganize all file by it (Reorganize reads it from the file again).
  • A legacyTakenAt, the reading older versions made in the server's zone, is computed too, so pairing still finds captures imported before this rule.

Tests in apps/api/src/uploads/exifTimezone.test.ts cover the explicit-offset case and server-zone independence. How exiftool-vendored ranks its own inference sources isn't tested by Lifer.

Videos use the same reader (apps/api/src/uploads/video.ts); their time comes from DateTimeOriginal only. Duration comes from FFmpeg.

Duplicates​

  • Exact: the SHA-256 of the whole file, computed while it's received (apps/api/src/lib/stagedUploads.ts, tusUploads.ts, uploads/fileFingerprint.ts) and stored as captures_all.fingerprint and originals.content_hash.
  • Near duplicates: when there's no exact match, a CLIP image vector with cosine similarity of 0.95 or more to an existing capture (packages/core/src/species/embeddings.ts).

Inspect reports either as a possible duplicate and the web app asks whether to import anyway. POST /api/uploads imports a duplicate unless the request sets skipDuplicates=1, in which case it returns the existing capture. Trip scans don't offer files whose hash is already known. The database doesn't enforce uniqueness (see Data model), because importing the same file twice on purpose is allowed. The EXIF fingerprint is for RAW pairing, not duplicate detection.

Choosing the species​

Nothing is assigned automatically at import. /api/captures/suggest-species and inspect only suggest (apps/api/src/captures/suggest.ts); the user confirms. Suggestions come from the identification model (BioCLIP 2) when it's downloaded, otherwise CLIP, on the detected animal's crop, pooled across a burst of similar frames, ranked against the region's checklist (or the user's own species and downloaded packs when there's no region), and adjusted for season, vagrancy and local rarity (packages/core/src/species/embeddings.ts). A keyword in the file that names exactly one species is put first. See ADR 0008 for where the models run.

Species are only assigned without the user in recovery: reimport (from keywords and names) and trip scans (from the trip's .lifer/index.json).

Where files go​

Store-mode imports file the original under the user's folder layout. The default (the Species preset) is: Every import path builds it through speciesFolder in apps/api/src/uploads/managedFolders.ts (layout in organizedPath.ts), so a species' photos, RAWs and videos always share one folder:

<Taxon>/<Species folder>/<RAW | Adjusted | Video>/<file>
  • <Taxon> is the group label, such as Birds or Mammals; Other Taxa use iNaturalist's group, or Other.
  • The folder levels and their order are per user (users.folder_layout, an ordered list of levels defined in packages/shared/src/folderLayout.ts, with presets for Species, Year, Date, Trip and Location). A level with no value for a photo is skipped, except Wildlife <year>, which keeps Wildlife Undated. The RAW, Adjusted or Video folder always comes last.
  • <Species folder> follows the user's naming styles (common name, scientific name, ABA or eBird code, or a combination; apps/api/src/uploads/speciesFolderName.ts). A common name shared with another species gets the scientific name added. Characters that aren't valid in file names are removed.
  • The base is the trip's destination folder for trip imports, a chosen drive's or library root's Lifer Originals folder, or the library (ORIGINALS_DIR). Under a trip's own folder the trip, country, province and place levels are left out; date levels still apply.

Files keep their own names. A clash gets -2, -3 and so on, up to 1000. Files are moved with a hard link and unlink, falling back to an exclusive copy: a move never overwrites (packages/core/src/lib/safeFs.ts). See ADR 0007.

A managed original always stays under the base it was filed under (locateManagedOriginal in apps/api/src/uploads/managedFolders.ts: its trip's destination folder when it's inside it, else its volume's Lifer Originals folder for a file on a drive or library root, else the library). When the user changes a photo's species (or a new photo claims an unmatched RAW) and the layout ends in group and species folders, only those change: the base and the folders above them stay as they are (moveManagedOriginalToSpeciesFolder). With any other layout, or for a file not in that layout, the file is refiled under its base with the current layout, and one outside every base Lifer knows, or on a drive that isn't connected, stays put. The move happens before the database changes and is undone if the transaction fails; a file on a volume keeps volume_id, with volume_relative_path updated; emptied species folders are removed. Unmanaged (linked) files never move. Reorganize existing photos in Settings > Library (POST /api/settings/reorganize-originals) refiles every managed original (hidden ones too, not trashed ones) under its own base with the current naming and folder layout, skipping files on disconnected drives. Reimport's "organize" is the one path that moves files into the library from elsewhere (fileIntoMainLibrary in apps/api/src/uploads/common.ts).

Previews​

generateDerivatives (packages/core/src/uploads/image.ts) decodes each photo once, rotated by its EXIF orientation, and writes three sRGB WebP files to APP_DATA_DIR: display/ (2560 px), medium/ (1024 px) and thumb/ (400 px), never enlarged. sharp converts a photo with an ICC profile to sRGB itself. HEIC, AVIF, JPEG 2000 and JPEG XL go through an upright sRGB working JPEG instead (DECODED_FORMATS, decodedJpeg.ts), which species matching reads too: libvips can't decode the others, and ignores the colour primaries an AVIF states in its nclx box. A gain map (HDR JPEG, AVIF or JPEG XL) is ignored, so previews show the SDR base. Videos get a poster frame, and an H.264 MP4 under video-preview/ when the original won't play in a browser. Previews are a cache: deleted with a failed import, and regenerated from the original when missing.

Metadata Lifer reads​

ReadFromUsed for
Capture time, GPS, camera, lens, exposureEXIFDisplay, search, maps, RAW pairing, year folders. Copied into captures_all once.
Rating (1 to 5)XMP:Rating in the file, else its sidecarcaptures_all.quality_rating at import and reimport
KeywordsKeywords, Subject, TagsList, HierarchicalSubject, and the sidecarSpecies suggestion, and species recovery on reimport
Cull marksRating -1, XMP-xmpDM:Pick and Good, digiKam pick and colour labels, Photo Mechanic tags, Lightroom and Bridge colour labelsSkip, hide or ignore rejects at import (below)

Cull marks​

Culling apps such as Lightroom, Photo Mechanic and digiKam mark photos as picks or rejects and give them colour labels. apps/api/src/uploads/cullMarks.ts normalises those into a verdict (pick or reject) and a label, merging the file and its sidecar, and a photo with its RAW; a reject anywhere wins. Stored as captures_all.cull_verdict and cull_label (M130).

At import the user chooses what a reject does: skip it, import it hidden (hidden_at set, out of every view until unhidden), or ignore the mark. Uploads default to ignore, trip imports and reimport to skip. Lifer never writes, deletes or moves a file because of a cull mark, and leaves a -1 rating in place when it has no rating of its own (apps/api/src/uploads/xmpSidecarSync.ts). Inspect in the browser sees only the file, since a browser upload carries no sidecar.

Metadata Lifer writes​

Lifer writes its species and rating back to files so the library stays meaningful without Lifer, and so a lost database can be rebuilt (ADR 0006). Everything goes through syncCaptureXmpSidecars (apps/api/src/uploads/xmpSidecarSync.ts) and writeCaptureMetadata (apps/api/src/uploads/exif.ts).

Only managed files are written: originals with managed = true. Linked files are never touched.

Where: inside JPEG, TIFF, PNG, DNG, WebP, HEIC, HEIF, AVIF, JP2, JPX and JPEG XL container files. For everything else, RAW, video and bare JPEG 2000 or JPEG XL codestreams (exiftool can't write those), a <name>.xmp sidecar next to the file.

What:

TagValue
XMP-dc:SubjectCommon name, scientific name, ABA code and eBird code of each species in the photo, Lifer:Cover if it's the species' cover photo, and the photo's own tags ("flight shot")
XMP-lr:HierarchicalSubjectSpecies|<Taxon>|<Family>|<name>, for example Species|Birds|Accipitridae|Bald Eagle, and Lifer Tags|<tag> for each photo tag
XMP-dc:TitleThe title template, by default {names}: every species in the naming style
XMP-photoshop:HeadlineThe headline template, empty (not written) by default
XMP-dc:DescriptionThe caption template, empty by default; XMP-photoshop:CaptionWriter "Lifer" when the whole caption is Lifer's
IPTC:Keywords, IPTC:ObjectName, IPTC:Headline, IPTC:Caption-Abstract, EXIF:ImageDescriptionThe same, embedded files only, always written together with the XMP value
XMP-xmp:RatingLifer's 1 to 5 rating; removed when the user clears it
XMP-exif:GPSLatitude, GPSLongitudeSidecars only

Templates and write rules. Title, Headline, Caption and extra Keywords each have a template (packages/shared/src/metadataTemplate.ts, filled by uploads/templateVars.ts, stored in install_settings under metadata_template:<userId> beside the credits, read by getMetadataFields in settings/metadataSettings.ts) and a rule: fillEmpty (write only into an empty field), replace (write over Lifer's own value, the default), append (after the file's own text, swapping Lifer's earlier addition) or off. Extra keywords are a comma separated template whose values go beside the species keywords. multiSpecies: "main" limits {names} and {count} to the main species; species keywords always list every species, since reimport recovers them. Missing settings read as the defaults, which write what Lifer wrote before templates. API: GET/PUT /api/settings/metadata-fields, GET /api/settings/metadata-preview (every field for a captureId, one of the user's recent photos, or a sample, with the token values so a draft renders the same in the app), and POST /api/settings/metadata-template/apply?dryRun=1, which counts the photos a write would change and those with a field kept because someone edited it.

Only Lifer's own values are replaced. capture_written_metadata (M199) holds the exact value Lifer last wrote into each templated field, per original and per file (slot: the file, its IMG.xmp sidecar or its IMG.CR3.xmp sidecar). Before a write, planLiferWrite in uploads/exif.ts reads the file: a value equal to the record is Lifer's and may change, any other non-empty value was edited elsewhere and stays (textFieldPlan, keywordPlan). Extra keywords are swapped only while every one Lifer added is still there, and one the file had before is never claimed. A file with no record (written before M199, or after a reimport) falls back to the in-file markers: the caption's CaptionWriter "Lifer", and a title made only of species names (current names or species_synonyms, which a catalog update adds a renamed species' old common name to, source renamed), codes and ranks; a headline is then left alone. A dry run lists the kept fields per photo (editedPhotos, current and wanted values, first 500), and Apply with overwriteCaptureIds writes over them for the photos the user chose. The record is written after the file, so a failure in between reads as an edit and nothing is overwritten.

Keywords from other tools are kept: only Lifer's own (species names and codes, Lifer:Cover, anything under Species|, and photo tags) are replaced. Photo tags are plain keywords, so other apps show them like any other; the Lifer Tags|<tag> entry beside each records that the keyword is Lifer's, so removing, renaming or deleting a tag in Lifer removes it from the file and never a keyword another app added (a | in a tag is written as / there). A keyword another app added with the same text as a Lifer tag goes with the tag. A write that doesn't carry the tags (a species-only rewrite) leaves them as they are. Reimport reads the Lifer Tags| entries back. Camera fields are never written: camera, lens and exposure are not part of the write, and neither is capture time, except a date set in Lifer on an embedded-metadata file without a camera date (written as a UTC wall clock, so a reimport reads back the same instant). A camera writes CreateDate beside DateTimeOriginal and Lifer writes only DateTimeOriginal, so a file with no DateTimeOriginal, or one without CreateDate (Lifer's own date, or a scan's), takes the date and later corrections; a file with both is never changed. exifMetadata.test.ts checks both.

How: exiftool -overwrite_original, one write at a time per file. ExifTool rewrites the file through a temp file and rename, so an interrupted write doesn't leave a half-written photo, but the file's modification time changes, which backup tools see as a change.

When: in the background after an upload commits, and after a change of species (including extra species), rating, cover, or tags (including renaming or deleting a tag on the Tags page), after a reorganize, and after a catalog update moves photos to a merged species. A failed write is logged or ignored and never fails the request, so files can lag behind the database. Trip imports and video uploads don't write at import; their files are written at the next change.

Recovery files in the library​

Besides tags, Lifer keeps a few small JSON files in .lifer folders, written atomically (apps/api/src/lib/atomicWrite.ts: a temp file flushed with fsync, renamed over the old one, then the folder flushed too, except on Windows, which can't open a folder for it):

FileHoldsWritten
<library>/.lifer/collection-state.jsonPer user (by email): seen species, archived and hidden species, targets, tier overrides, checklist additions. Species by scientific name.Two seconds after a change to any of these (apps/api/src/lib/collectionState.ts)
.lifer/albums.json in each photo folder, and in the taxon folder aboveWhich albums each photo is in, by album nameOn album add and remove (apps/api/src/albums/albumIndex.ts)
<trip destination>/.lifer/index.jsonThe species of each imported trip photo, by relative pathAfter each trip import (apps/api/src/trips/tripIndex.ts)

How they're read back is in State and sync.