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
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)
}
Value of type 'StorageMetadata' has no member 'downloadURL'
Can you try
// 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)
}
})
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
How to Remove the Left and Right Padding of a List in Swiftui
Swift 4 Decodable - Dictionary With Enum as Key
Nsfilemanager Fileexistsatpath:Isdirectory and Swift
Why Do Self and Self Sometimes Refer to Different Types in Static Functions
Noop For Swift'S Exhaustive Switch Statements
Difference Between Flatmap and Compactmap in Swift
Swift Structs to Nsdata and Back
How to Convert Array of Bytes [Uint8] into Hexa String in Swift
Trapping Signals in a Swift Command Line Application
Extra Arguments At Positions #11, #12 in Call Swiftui
Swift - Validating Uitextfield
Selecting Global or Object Print Function
Separating Multiple If Conditions With Commas in Swift
Knowing Where Retain Cycles Are and Removing Them