Skip to main content

im trying to download a file but am getting a 404 error, "not found".  Im thinking that the file-id is not supposed to be the file name of the file I'm trying to download from my BOX account. heres my code:

let contentClient = BOXContentClient.default()
let localFilePath: String = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("savedClients.data").absoluteString
let boxRequest: BOXFileDownloadRequest? = contentClient?.fileDownloadRequest(withID: "savedClients.data", toLocalFilePath: localFilePath)
boxRequest?.perform(progress: {(_ totalBytesTransferred: Int64, _ totalBytesExpectedToTransfer: Int64) -> Void in
// Update a progress bar, etc.
}, completion: {(_ error: Error?) -> Void in
// Download has completed. If it failed, error will contain reason (e.g. network connection)
if error == nil {
print("------------ \nCardSelection VC: Downloaded savedClients.data file")
if let savedClientsData = FileManager.default.contents(atPath: localFilePath) {
if let model = NSKeyedUnarchiver.unarchiveObject(with: savedClientsData) as? ClientModel] {
self.savedClients = model
self.reloadData()
UIApplication.shared.isNetworkActivityIndicatorVisible = false
}
}
} else {
print("-------------\nCardSelection VC: BOX error downloading savedClients file: \(String(describing: error))")
UIApplication.shared.isNetworkActivityIndicatorVisible = false
let alert = UIAlertController(title: "Error", message: "There was an error downloading saved clients file from BOX:\(String(describing: error))", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dismiss", style: .default, handler: nil)
alert.addAction(dismiss)
self.present(alert, animated: true, completion: nil)
}
})

 As you mentioned, the Download File endpoint uses a file's id and not its name as the primary identifier. File id is in the format of "123456".



ok thats what i thought.  what is the proper way to get the file id then.  I'm using swift but can also read c#.  From what i found, i have to get the folder and then get the file from there.  So this brings up the same problem.  To get the folder, i need the folder id as well.  so I'm stumped as to how i get the id's so actually search/download folders and files.  Thanks in advance for your help. 



 There are a few ways to get a file's id:


  • When you upload a file, the API returns back the file id in the response. 

  • You can search for a file by its name using the Search endpoint

  • You can query the User Events endpoint for ITEM_UPLOAD events. This will return a list of recently uploaded files with their ids.

  • If you know the folder id where the file was uploaded, you can call the Get Folder Items endpoint.


awesome thank you!!



Reply