Copy imported files before sending to preserve access

This commit is contained in:
jack
2025-10-15 17:37:18 +01:00
committed by islam
parent cd39d8c8c0
commit a5a3efebcb
+14 -2
View File
@@ -2112,8 +2112,20 @@ private extension ContentView {
}
func handleImportedFile(url: URL) async {
await MainActor.run {
viewModel.sendFileAttachment(from: url)
do {
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)
}
}