Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WirecardMobileServices/e2c6e9389863ce24727d6af84c952500 to your computer and use it in GitHub Desktop.
Save WirecardMobileServices/e2c6e9389863ce24727d6af84c952500 to your computer and use it in GitHub Desktop.
Download a previously uploaded file by its ID
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