Downloadurl()' Is Deprecated: Use 'Storagereference.Downloadurlwithcompletion()' to Obtain a Current Download Url

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)
}
}
}
}

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
}
})

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)
}

})
})

Kingfisher: Ambiguous use of 'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)'

That error is because you need to handle the completionHandler instead of passing nil. Try below code:

button.kf.setBackgroundImage(with: URL(string: picture), for: .normal, placeholder: nil, options: options, progressBlock: nil) { result in
// result is either a .success(RetrieveImageResult) or a .failure(KingfisherError)
switch result {
case .success(let value):
// The image was set to image view:
print(value.image)

// From where the image was retrieved:
// - .none - Just downloaded.
// - .memory - Got from memory cache.
// - .disk - Got from disk cache.
print(value.cacheType)

// The source object which contains information like `url`.
print(value.source)

case .failure(let error):
print(error) // The error happens
}
}

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