Copy imported files before sending to preserve access

This commit is contained in:
jack
2025-10-15 00:37:40 +01:00
committed by islam
parent f607413caf
commit f145d13992
+14 -2
View File
@@ -2055,8 +2055,20 @@ private extension ContentView {
} }
func handleImportedFile(url: URL) async { func handleImportedFile(url: URL) async {
await MainActor.run { do {
viewModel.sendFileAttachment(from: url) let fileManager = FileManager.default
let tempDir = fileManager.temporaryDirectory
let fileName = url.lastPathComponent.isEmpty ? "attachment" : url.lastPathComponent
let destination = tempDir.appendingPathComponent(UUID().uuidString + "_" + fileName)
if fileManager.fileExists(atPath: destination.path) {
try fileManager.removeItem(at: destination)
}
try fileManager.copyItem(at: url, to: destination)
await MainActor.run {
viewModel.sendFileAttachment(from: destination)
}
} catch {
SecureLogger.error("File copy failed before send: \(error)", category: .session)
} }
} }