I want to upload two copies of each image, one fullsize and one thumbnail. I have looked for answers here on SO and the Firebase docs.
With the code below, only the thumbnail image is saved to storage. How can I fix it so that both images are uploaded? Obviously I haven't fully understood how to work with returns/closures. Help much appreciated!
This series of methods gets called when user taps the upload button
self.uploadAndGetFullSizeImageDownloadURL(completion: { (url) in
print("Fullsize URL: \(url) is stored")
self.fullSizeDownloadURL = url
self.uploadAndGetThumbNailImageDownloadURL(completion: { (url) in
print("Thumbnail URL: \(url) is stored")
self.thumbNailDownloadURL = url
// Save image info to database
self.saveImageInfoToDatabase(fullSizeURL: self.fullSizeDownloadURL, thumbNailURL: self.thumbNailDownloadURL, completion: { (finished) in
...
})
})
})
The methods for uploading and getting the URLs look like this:
func uploadAndGetFullSizeImageDownloadURL(completion: @escaping (String) -> Void) {
var fullUrlStr = ""
// Get imageData
let fullSizeImageData = self.getImageData(size: "fullSize")
// Upload fullsize image to storage
let fullSizeStorageRef = self.sRef.child("\(String(describing: uid!)), \(createdAt!)")
fullSizeStorageRef.putData(fullSizeImageData, metadata: nil, completion: {
(metadata, error) in
print("Fullsize image is stored")
// Get the fullsize downloadURL
fullSizeStorageRef.downloadURL(completion: { (url, error) in
if let downloadURL = url?.absoluteString {
fullUrlStr = downloadURL
//Return fullsize downloadURL
completion(fullUrlStr)
}
})
})
}
print("Fullsize URL: \(url) is stored")
andprint("Thumbnail URL: \(url) is stored")
β vauxhall