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:4Type Definition
Identifiable- For use in SwiftUI lists with stable identityCodable- For JSON serialization to UserDefaultsSendable- For safe passing across actor boundaries
Properties
id
Unique identifier for the upload item.Auto-generated UUID for stable identity in SwiftUI lists.
fileName
Original name of the uploaded file.The original filename (e.g.,
"photo.jpg", "document.pdf").fileSize
Size of the uploaded file in bytes.File size in bytes. Used for displaying formatted size to users.
r2Key
The object key used in R2 storage.The full R2 object key (e.g.,
"abc12345-photo.jpg", "uploads/2024/document.pdf").uploadDate
Timestamp when the upload completed.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.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."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.Original filename of the uploaded file.
Size of the file in bytes.
The R2 object key where the file is stored.
Public URL for accessing the uploaded file.
Implementation Details
- Generates a new UUID for the
id - Stores the provided parameters
- Sets
uploadDateto the current date/time
Usage Example
SwiftUI List Integration
Adding to History Store
JSON Encoding
The model automatically encodes to JSON viaCodable:
Sendable Conformance
Identifiable Conformance
Theid property satisfies Identifiable for SwiftUI:
id to:
- Track items across updates
- Animate insertions/deletions
- Maintain selection state
File Size Formatting Examples
Design Considerations
Why UUID instead of timestamp for ID?
Why UUID instead of timestamp for ID?
UUIDs provide guaranteed uniqueness even if multiple uploads complete in the same millisecond. Timestamps could collide.
Why store publicURL instead of regenerating?
Why store publicURL instead of regenerating?
The URL may depend on custom domain settings that could change. Storing ensures the URL remains valid even if configuration changes.
Why Int64 for fileSize?
Why Int64 for fileSize?
Supports files up to 8 exabytes. Int would be limited to 2 GB on some architectures.
Why immutable properties?
Why immutable properties?
Upload history entries represent completed events that shouldn’t change. Immutability prevents accidental modification.
Related Services
- UploadHistoryStore - Manages collections of UploadItems
- R2UploadService - Creates UploadItems after successful uploads
- FileUploadTask - Represents in-progress uploads