Created
September 16, 2019 13:17
-
-
Save WirecardMobileServices/e2c6e9389863ce24727d6af84c952500 to your computer and use it in GitHub Desktop.
Download a previously uploaded file by its ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let sdk: WDePOS = WDePOS.sharedInstance() | |
//Example for getting a zip of receipt images previously uploaded | |
sdk.fileManager.files("merchantId", category: "receiptImages") { (files, error) in | |
if error != nil || files == nil { | |
//Unknown error when loading receipt images - \(error?.localizedDescription ?? "")") | |
return | |
} | |
guard let files = files, let file = files.first, let fileId = file.internalId, let fileName = file.originalFileName else { | |
//"Error when loading receipt images - No files in category | |
return | |
} | |
guard files.count == 1 else { | |
//"Error when loading receipt images - More than one archive found | |
return | |
} | |
guard file.originalFileName?.caseInsensitiveCompare("receiptImages.zip") == .orderedSame else { | |
//"Error when loading receipt images - Invalid archive name | |
return | |
} | |
//Once we have a valid fileId we can download the file itself | |
sdk.fileManager.downloadFile(fileId, completion: { (fileDownload, error) in | |
guard let filePath = fileDownload?.filePath, error == nil else { | |
//Unknown error when downloading receipt images - \(error?.localizedDescription ?? "") | |
completion(.failure(.unknownError(error))) | |
return | |
} | |
guard let urlPath = URL(string: filePath) else { | |
//"Unknown error when downloading receipt images - Invalid file path | |
completion(.failure(.unknownError(nil))) | |
return | |
} | |
completion(.success(urlPath)) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment