diff --git a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift index 40d952e1d4b8f3bff37083e1695665537c1d91d5..05e8ad2a0e91ac5ddc7fb15e6d65e3acc14314e0 100644 --- a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift +++ b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsModel.swift @@ -22,6 +22,21 @@ struct Attachment: DisplayAttachment, Equatable { myID = UUID() } + /// download calling attachment into the documents diectory + func download(){ + func getDocumentsDirectory() -> URL { + let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) + return paths[0] + } + let filename = getDocumentsDirectory().appendingPathComponent(self.myName) + + do { + try self.myData.write(to: filename) + } catch let error as NSError { + print("Error: \(error)") + } + } + /// a func that returns the size of the calling attachment file as a string func countData() -> String { // size in byte diff --git a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift index 2069615105100aaa22f25f0bddf5ba5ba04ab73b..2789fcc8e9db79c8832c7ca838b9c56bea40b5d0 100644 --- a/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift +++ b/enzevalos_iphone/SwiftUI/Compose/AddAttachmentsView.swift @@ -113,6 +113,10 @@ struct AddAttachmentsView: View { // create Attachment and add in to the attachments list let newAttachment = Attachment(fileName: fileName, fileData: fileData) model.attachments.append(newAttachment) + // download the file into the documents directory + // this is necessary, because the QuickLookView later uses that data + // to create a preview + newAttachment.download() } catch { // Error while loading file print("Error while importing file.")