I need to download a pdf from the storage and save it locally on an iOS device, so it can be seen in Files.
Here is the code is taken from the docs, which I'm using:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let userID = Auth.auth().currentUser!.uid
print(userID)
// Get a reference to the storage service using the default Firebase App
let storage = Storage.storage()
// Create a storage reference from our storage service
let storageRef = storage.reference()
// Create a reference to the file you want to download
let islandRef = storageRef.child("pdf/sample.pdf")
// Create local filesystem URL
let localURL = URL(string: "pdf/sample.pdf")!
// Download to the local filesystem
let downloadTask = islandRef.write(toFile: localURL) { url, error in
if let error = error {
// Uh-oh, an error occurred!
} else {
// Local file URL for "images/island.jpg" is returned
}
}
}
When I try to run this ViewController, it doesn't crash but throws the following error:
"The file couldn’t be opened because the specified URL type isn’t supported." UserInfo={NSURL=pdf/sample.pdf}
The file in the Firebase Storage is saved in a folder called pdf/sample.pdf
. Eventually, I wish to take the reference from the storage and pass it in a RealtimeDatabase
, so the user can download it by viewing details about it in a table view.