Batch Import Multiple Images
Allow users to select multiple photos from gallery and get file paths for processing or uploading.
Actions Required
Variables Needed
tempDirectory (String) = "ImportedMedia" (optional)
tempBaseFileName (String) = "photo" (optional)
Implementation Steps
1. State: SelectMultiplePhotos
Action: MediaServicesSelectContent
Inputs:
allowsMultipleSelection: true
maxCount: 5 (limit to 5 photos)
Events:
successEvent β GetSelectionCount
failureEvent β HandleCancellationOrError
2. State: GetSelectionCount
Action: MediaServicesGetSelectContentSuccessResult
Outputs:
contentCount β contentCount
3. State: LoopStart
Logic: Int Compare
If currentIndex < contentCount β GetFilePath
If currentIndex >= contentCount β ProcessComplete
4. State: GetFilePath
Action: MediaServicesGetContentFilePath
Inputs:
contentIndex: currentIndex
tempDirectory: tempDirectory
tempFileName: tempBaseFileName
Outputs:
filePath β filePath variable
Next: This action finishes when the file path is ready. Use the stateβs FINISHED transition β ProcessFilePath (or StoreFilePath).
5. State: ProcessFilePath
Use filePath immediately (upload/process/move to persistent storage), then:
6. State: ProcessComplete
All selected items processed.
Batch Import Flow
File Path Usage
Local Processing:
Server Upload:
Temporary Files: Paths point to a temp cache; copy/move to Application.persistentDataPath if you need them long-term
Copy to Persistent: Move files to Application.persistentDataPath if needed long-term
Large Batches: Limit maxCount to prevent memory issues (recommend 5-10 max)
File Format: Images may be in various formats (JPG, PNG, HEIC); handle accordingly
iOS:
Files are copied to app's temp directory
HEIC format common on newer devices (may need conversion)
Android:
Files may reference original gallery locations
Permissions required to read external storage
Background Processing:
Process files off main thread to prevent UI freezing
Show progress bar for large batches
Progressive Upload:
Upload files one at a time with progress feedback
Allow cancellation during upload
Memory Management:
Don't load all images into memory simultaneously
Process and release one at a time
Photo Album Creation:
App creates collage or album
Batch Upload:
User selects multiple photos
Track upload status per file
Optional (upload bytes instead of files)
If you donβt want file paths, use MediaServicesGetContentRawMediaData per index to get rawBytes + mimeType and upload directly.
Last updated