Value of type 'StorageMetadata' has no member 'downloadURL'
You've probably updated your Firebase pods. In Firebase 5.0 they got rid of the metaData?.downladURL()
function. You have to follow the updated docs on their website. Copying from there:
// Data in memory
let data = Data()
// Create a reference to the file you want to upload
let riversRef = storageRef.child("images/rivers.jpg")
// Upload the file to the path "images/rivers.jpg"
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can also access to download URL after upload.
riversRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
return
}
}
}
Firebase Storage: https://firebase.google.com/docs/storage/ios/upload-files
Value of type 'StorageMetadata' has no member 'downloadURL'
Can you try Google Firebase docs
// Create a reference to the file you want to download
let starsRef = storageRef.child("images/stars.jpg")
// Fetch the download URL
starsRef.downloadURL { url, error in
if let error = error {
// Handle any errors
} else {
// Get the download URL for 'images/stars.jpg'
}
}
Why after updating pods do I keep getting Value of type 'StorageMetadata' has no member 'downloadURL'?
You're getting:
Value of type 'StorageMetadata' has no member 'downloadURL'
If you look at the documentation for StorageMetadata
you'll see that it indeed doesn't have a downloadURL
member. This member was dropped in the SDK updates of May 2018, so is long gone.
The correct way to get the download URL is shown in the documentation on uploading data:
// Upload the file to the path "images/rivers.jpg"
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can also access to download URL after upload.
riversRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
return
}
}
}
In your case, that'd be something like:
newImageRef.putData(imageData).observe(.success, handler: {(snapshot) in
newImageRef.downloadURL { (url, error) in
guard let downloadURL = url else {
return
}
newPostRef.setValue(url)
}
})
it throws this error: Value of type 'StorageMetadata' has no member 'downloadURL'
As per Firebase doc, you may there is no direct property downloadURL
in StorageMetadata
class. So you may have to use dictionaryRepresentation
and access download link using mediaLink key.
Example:
if let downloadURL = metadata.dictionaryRepresentation()["mediaLink"] as? String{
self.setUser(img:downloadURL)
}
Chat: Value of type 'StorageMetadata' has no member 'downloadURLs'
StorageMetadata doesn't have a property called downloadURLs, as you can seem from the API documentation. That's been deprecated a long time ago and removed from the API. You're probably looking at an old example or tutorial.
If you need to generate a download URL for a file in Cloud Storage, use downloadURL() to fetch one.
Related Topics
Swift iOS14 Datepicker Text Alignment
Preferredstatusbarupdateanimation Being Ignored
Swift - How to Deal with Uncaught Exception
Nstoolbarflexiblespaceitem Is Constraint to Nssplitviewitem in Swift
Wkwebview Won't Load (Nsviewcontroller, Os X)
Swift Difference Between Double and Float64
Decoding a Nested Array in Swift 4
How to Access The Firebase Topics a User Is Subscribed To
Variable with Getter/Setter Cannot Have Initial Value, on Overridden Stored Property
Mapping Swift Combine Future to Another Future
Cannot Assign to Value: 'self' Is Immutable
Can't Load Images on MAC Screensaver Release Build (It Works on Xcode Debug Build)
Xcode Failed to Resolve Dependency Firebase - Googleappmeasurement Does Not Match Requirement
Why Does Cabasicanimation Try to Initialize Another Instance of My Custom Calayer
Set Multiple Arrow Directions on UIpopovercontroller in Swift