[英]Access Firebase storage images based on uids
我有一個應用程序,將每個用戶的個人資料圖片存儲在Firebase存儲中。 這是我用來存儲個人資料圖片的路徑:
FIRStorage.storage().reference(forURL: "gs://gsignme-15916.appspot.com").child(user.uid+"/profile_pic.jpg")
我也使用圖像的URL將圖像存儲在firebase數據庫中。但是當我嘗試使用此代碼訪問個人資料圖片時。
if (post["uid"] as? String) != nil {
let imageRef = FIRStorage.storage().reference().child((uid)!+"/profile_pic.jpg")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
if error == nil {
let image = UIImage(data: data!)
cell.UserImg.image = image
cell.UserImg.layer.cornerRadius = 10
cell.UserImg.clipsToBounds = true
}else {
print("Error downloading image:" )
}})}
我更改了用戶,圖片更改為當前用戶的圖片,而不是發帖的用戶。 我知道問題在於如何檢索圖像,但是我不確定如何根據不是當前登錄用戶的uid檢索圖像。
這應該非常簡單-盡管您應該添加一些檢查以確保最終不會為uidPoster添加空字符串
if (post["uid"] as? String) != nil {
let uidPoster = post["uid"] as? String
let imageRef = FIRStorage.storage().reference().child((uidPoster)!+"/profile_pic.jpg")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
if error == nil {
let image = UIImage(data: data!)
cell.UserImg.image = image
cell.UserImg.layer.cornerRadius = 10
cell.UserImg.clipsToBounds = true
}else {
print("Error downloading image:" )
}})}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.