Skip to main content

Overview

UploadItem represents a single completed upload in the upload history. It stores metadata about the uploaded file including its name, size, R2 key, upload date, and public URL. The model conforms to Identifiable for SwiftUI list display and Codable for JSON persistence.
Located at: Fiaxe/Models/UploadItem.swift:4

Type Definition

A value type that conforms to:
  • Identifiable - For use in SwiftUI lists with stable identity
  • Codable - For JSON serialization to UserDefaults
  • Sendable - For safe passing across actor boundaries

Properties

id

Unique identifier for the upload item.
UUID
Auto-generated UUID for stable identity in SwiftUI lists.

fileName

Original name of the uploaded file.
String
The original filename (e.g., "photo.jpg", "document.pdf").

fileSize

Size of the uploaded file in bytes.
Int64
File size in bytes. Used for displaying formatted size to users.

r2Key

The object key used in R2 storage.
String
The full R2 object key (e.g., "abc12345-photo.jpg", "uploads/2024/document.pdf").

uploadDate

Timestamp when the upload completed.
Date
The date and time when the upload completed. Automatically set to current time during initialization.
Property NameThe property is named uploadDate, not timestamp. This matches the actual source code implementation.

publicURL

Public URL for accessing the uploaded file.
URL
The public URL where the file can be accessed (e.g., custom domain URL or R2 public URL).

Computed Properties

formattedFileSize

Human-readable file size string.
Returns: Formatted string like "2.1 MB", "456 KB", "1.2 GB". Uses Foundation’s ByteCountFormatter for localized, user-friendly formatting.

Initializer

Creates a new upload item with automatic ID and timestamp generation.
String
required
Original filename of the uploaded file.
Int64
required
Size of the file in bytes.
String
required
The R2 object key where the file is stored.
URL
required
Public URL for accessing the uploaded file.

Implementation Details

The initializer:
  1. Generates a new UUID for the id
  2. Stores the provided parameters
  3. Sets uploadDate to the current date/time

Usage Example

SwiftUI List Integration

Adding to History Store

JSON Encoding

The model automatically encodes to JSON via Codable:
Used by UploadHistoryStore for persistence.

Sendable Conformance

Thread SafetyThe Sendable conformance allows passing UploadItem across actor boundaries:
All properties are value types or immutable, making this safe.

Identifiable Conformance

The id property satisfies Identifiable for SwiftUI:
SwiftUI uses the id to:
  • Track items across updates
  • Animate insertions/deletions
  • Maintain selection state

File Size Formatting Examples

Design Considerations

UUIDs provide guaranteed uniqueness even if multiple uploads complete in the same millisecond. Timestamps could collide.
The URL may depend on custom domain settings that could change. Storing ensures the URL remains valid even if configuration changes.
Supports files up to 8 exabytes. Int would be limited to 2 GB on some architectures.
Upload history entries represent completed events that shouldn’t change. Immutability prevents accidental modification.