I'm trying to import a folder from iCloud with Document Picker to upload it to a server, using Alamofire. I can import a single file like .txt .pdf
files from iCloud, but I can't pick a folder which has some files in it. I'm getting the following error after trying to select a folder:
Unable to load data: Error Domain=NSCocoaErrorDomain Code=257 "The file “xxxx” couldn’t be opened because you don’t have permission to view it." ... {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}
And here is my code:
someFunctionToGetPickedFilePath = { (filePath) in
let urlString = filePath.path
let fileWithPath: URL = URL.init(fileURLWithPath: urlString)
do {
let fileData = try Data(contentsOf: fileWithPath)
// upload the fileData to server with Alamofire upload request
} catch {
print("Unable to load data: \(error)")
}
}
"filePath" URL in here comes from document picker function like this:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
// some code
}
I am trying to find a solution for almost 2 days but I cannot seem to find a solution. How can I pick a folder from iCloud and why am I getting this permission denied error? Any response will be highly appreciated.