Skip to content

Commit a74e9ec

Browse files
committed
Coordinate file read in resolveRelativePath
Otherwise we can't get a bookmark
1 parent 09e96ee commit a74e9ec

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

ios/Classes/SwiftFilePickerWritablePlugin.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,24 @@ public class SwiftFilePickerWritablePlugin: NSObject, FlutterPlugin {
173173
}
174174
let childUrl = url.appendingPathComponent(relativePath).standardized
175175
logDebug("Resolved to \(childUrl)")
176+
var coordError: NSError? = nil
177+
var bookmarkError: Error? = nil
178+
var identifier: String? = nil
179+
// Coordinate reading the item here because it might be a
180+
// not-yet-downloaded file, in which case we can't get a bookmark for
181+
// it--bookmarkData() fails with a "file doesn't exist" error
182+
NSFileCoordinator().coordinate(readingItemAt: childUrl, error: &coordError) { url in
183+
do {
184+
identifier = try childUrl.bookmarkData().base64EncodedString()
185+
} catch let error {
186+
bookmarkError = error
187+
}
188+
}
189+
if let error = coordError ?? bookmarkError {
190+
throw error
191+
}
176192
result([
177-
"identifier": try childUrl.bookmarkData().base64EncodedString(),
193+
"identifier": identifier,
178194
"persistable": "true",
179195
"uri": childUrl.absoluteString,
180196
"fileName": childUrl.lastPathComponent,

0 commit comments

Comments
 (0)