0

hope you are doing good in development. I have a question regarding Zipping currently i am using Zip framework which I am using for zip the all captured image in device but the problem here is I do not want to save the Zip file in document directory instead I wanna save this memory itself. I am struggling since last week please let me know how can we achieve the zipping without saving it in local directory filepath

Also when I captured the image successfully I saved it to local directory using

let documentsDirectory = FileManager.default.urls(for:
.documentDirectory, in: .userDomainMask).first!

let fileName = "image.jpg"

let fileURL = documentsDirectory.appendingPathComponent(fileName)

if let data = UIImageJPEGRepresentation(image, 1.0),
  !FileManager.default.fileExists(atPath: fileURL.path) {
    do {
        // writes the image data to disk
        try data.write(to: fileURL)
        print("file saved")
    } catch {
        print("error saving file:", error)
    }
}

After when I am trying to send the image before our server I want to make it all one file so I have implemented the Zip (framework) Here filpathArray meant all captured image in local path

do {
    var urls = [URL]()

    for i in 0..<(self.filePathArray.count)
    {
        urls.append(self.filePathArray[i] as! URL)
    }

    if self.filePathArray.count > 0 {
        let zipFiles = try Zip.quickZipFiles(urls, fileName: "AllFiles")
    }
}

Here zipping is done successfully but it saved in local path so when using app container I can able to see the images, I do not want to see the images in device like apple sandbox or Xcode container itself

I want to make zipping on the flow like without saving it document directory, Thanks in advance.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
Arun
  • 91
  • 9
  • https://stackoverflow.com/a/16290117/8810022 , i think you are looking for this. – Harjot Singh Dec 25 '18 at 11:56
  • You might consider deleting them immediately after operation is done, instead of trying not to save them – Arik Segal Dec 25 '18 at 12:21
  • It is not clear what you asking here. If your intent it is only to save it in a local where the user don't see this zipped file you can use your App preferences folder inside your Library folder. If you don't want to keep the file after uploading it you can use a temporary folder – Leo Dabus Dec 25 '18 at 12:28
  • When doing penetration test these zipped images are seen by testers. In order to avoid that i want to save the zip file in memory instead directory path or any other So please provide some example i am desperately need please guide me – Arun Dec 25 '18 at 12:37
  • You might consider deleting them immediately after operation is done, instead of trying not to save them ? Yes we can but if upload to server is failed due to any reason user should do this by retry option so that i am just making the network call again where i am accounting all those images again, – Arun Dec 25 '18 at 12:40
  • you can't "save" in memory. You can't have an URL pointing to memory instead of pointing to disk – Leo Dabus Dec 25 '18 at 13:01
  • Is there any other solution out there ? My goal is documents and zip files are should not be visible in app sandbox or Xcode container. Please help me. – Arun Dec 25 '18 at 13:39
  • https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html – Leo Dabus Dec 25 '18 at 13:59
  • **Library** This is the top-level directory for any files that are not user data files. You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories. Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files. The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud. – Leo Dabus Dec 25 '18 at 14:00
  • Thanks for your answer Leo. If i save the files to Library document directory again it is visible in app container Xcode itself. So i assumed this might be visible in App sandbox. isn't it ? – Arun Dec 25 '18 at 15:42

0 Answers0