Firebase Storage Warning: downloadURL()' is deprecated: Use `StorageReference.downloadURLWithCompletion()
Basically not using the metadata but instead just getting the url after the success of your observe event. Since it's successful and you know it's there, you can download the URL. It's there in their docs to 'Generate a download URL'. Below, I'm assuming your StorageReference is uploadProfilePicTask.
uploadProfilePicTask.downloadURL(completion: { (url, error) in
if (error == nil) {
if let downloadUrl = url {
// Make you download string
let downloadString = downloadUrl.absoluteString
}
} else {
// Do something if error
}
})
downloadURL()' is deprecated: Use `StorageReference.downloadURLWithCompletion()` to obtain a current download URL.?
The error says that you need to use StorageReference.downloadURLWithCompletion()
well you need to use it:
let storageItem = Storage.storage().reference().child(ImageUid)
storageItem.putData(ImageData, metadata: metadata) { (metadata, error) in
if error != nil {
print("Couldn't Upload Image")
} else {
print("Uploaded")
storageItem.downloadURL(completion: { (url, error) in
if error != nil {
print(error!)
return
}
if url != nil {
self.SetUpUser(Image: url!.absoluteString)
}
}
}
}
Update for metadata?.downloadURL().absoluteString that returns a String
The metadata.downloadURL
no longer exists (and hasn't existed in SDKs released since May 2018). To get the download URL you now have to call downloadURL()
on the storage reference and then use the URL in the callback.
So the place to put your own code that needs the download URL is right where it now says //Do something with url
in the code you got from the documentation. If you want to pass that URL to your `` method, that'd looks something like:
storageRef.putData(imageData, metadata: nil, completion: {(metadata, error) in
if error != nil {
ProgressHUD.showError(error!.localizedDescription)
return
}
//*********** Need to fix this **************
let photoUrl = storageRef.downloadURL(completion: {url, error in
if error != nil {
print("Failed to download url:", error!)
return
} else {
self.sendDatatoDatabase(photoUrl: url)
}
})
})
Retrieve Firebase storage image without getting downloadurl flutter
If you're using the FlutterFire Storage library in your app, you can call getData
on a reference to the file to get its data. So with that you just need to know the path to the data, and you won't need the download URL in your application. Once you have the data locally, you can create an image out of it with: Converting a byte array to image in Flutter?
Unlike download URLs, the call to getData()
is checked by security rules, so you'll have to ensure that the user is permitted to access the file.
Firebase storage downloadURL partial apply forwarder for @nonobjc message
have a look at it I am here uploading a profile image to firebase storage
if let uploadData = UIImagePNGRepresentation(self.profileImageView.image!) {
storageRef.putData(uploadData, metadata: nil, completion: { (metadata, error) in
if let error = error
{
print(error)
return
}
else
{
//get download url if upload is successful
let downloadURL = metadata?.downloadURL()?.absoluteString
print(downloadURL!)
}
})
}
Related Topics
Xcode 9: Swift Dependency Analysis Error
Error "Call Can Throw, But Is Not Marked with 'Try' and the Error Is Not Handled"
Adding a Target to a Button Programmatically Throws an Error "Unrecognized Selector Sent to Class"
Modifing One Variable from Another View Controller Swift
Google Signin Cocoapods Deprecated
iOS 10.3 - How to Change App Icon Programmatically
Why Does It Take Such a Long Time for UI to Be Updated from Background Thread
Fbsdk (New Facebook Sdk 4.0) Implementation Is Not Working for Login with Facebook
Swift 3 Filter Array of Dictionaries by String Value of Key in Dictionary
Invert Calayer Mask That Is Based on a Stroke (No Fill)
How to Change Uinavigationbar Per View Controller
Pausing Timer When App Is in Background State Swift
iOS PDFkit Displaymode = Singlepage Only Shows the First Page of the PDF
Passing Data Between Interface Controllers in Watchkit