Reputation:
I have code which saves multiple images into firebase. I updated my pods, and after this I had to change my downloadURL code. After doing so the urls are not showing up in the database, neither is the “post section of it. This questions seems to be similar to this one. In the console I am getting the following errors:
Error Domain=FIRStorageErrorDomain Code=-13010 "Object [email protected]/post/string#.string#.jpg does not exist." UserInfo={[email protected]/post/string#.string#.jpg, ResponseBody={
And:
}, bucket=yubipracticearraybasicimg1.appspot.com, data=<7ba2020 2265722 6f72223a 207b020 20202022 636f465 2232034 30342c0a 20202020 226d6573 73616765 223a2022 4e6f420 46f756e 642e2020 436f56c 642066f 7426765 7406f62 6a656374 220a2020 7d0a7d>, data_content_type=application/json; charset=UTF-8, NSLocalizedDescription=Object [email protected]/post/string#.string#.jpg does not exist., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=404}
These both happen after I press a button which send the data to firebase. Below is the problematic code:
Block 1:
storageRef.downloadURL { (url, error) in
if error != nil {
print("Failed to download url:", error!)
return
}
let imageUrl = "\(String(describing: url))"
postRef.child(autoID).setValue(imageUrl)
}
Block 2:
storageRef.downloadURL { (url, error) in
if error != nil {
print("Failed to download url:", error!)
return
}
let imageUrl = "\(String(describing: url))"
// let value = ["Image\(self.number)": imageUrl] as [String : Any]
let value = [autoID: imageUrl] as [String : Any]
postRef.updateChildValues(value)
}
Thanks in advance for any help!
Upvotes: 0
Views: 841
Reputation:
You are probably using a different URL storage ref for the put data method the two blocks are within.
You may have something like this where childStorageRef is a different ref than storageRef:
childStorageRef.putData(uploadData, metadata: nil) { (metadata, err) in
storageRef.downloadURL { (url, error) in
if error != nil {
print("Failed to download url:", error!)
return
}
let imageUrl = "\(String(describing: url))"
postRef.child(autoID).setValue(imageUrl)
}
}
Change that ref to this:
storageRef.putData(uploadData, metadata: nil) { (metadata, err) in
storageRef.downloadURL { (url, error) in
if error != nil {
print("Failed to download url:", error!)
return
}
let imageUrl = "\(String(describing: url))"
postRef.child(autoID).setValue(imageUrl)
}
}
Same thing for block 2. Hope this helps!
Upvotes: 1