Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 1.07 KB

File metadata and controls

28 lines (18 loc) · 1.07 KB

Downloads

Downloads module is used to download files from Box.

Download a File

To download a file to your device(local disk), call client.downloads.downloadFile(fileId:downloadDestinationURL:queryParams:headers) method with the ID of the file to download and a URL to the location (including name of the file) where the file should be downloaded to.

let downloadsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let destinationURL = downloadsDirectoryURL.appendingPathComponent("file.txt")

let url = try await client.downloads.downloadFile(fileId: file.id, downloadDestinationURL: destinationURL)

if let fileContent = try? String(contentsOf: url, encoding: .utf8) {
    print("The content of the file: \(fileContent)")
}