Firebase Storage Warning: Downloadurl()' Is Deprecated: Use 'Storagereference.Downloadurlwithcompletion()

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



Leave a reply



Submit