diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index 193823fe..4539b02c 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -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) } }