从 Firebase 存储中获取图像
Getting images from Firebase storage
我正在尝试从 Firebase
存储中获取图像。我必须得到与 JSON
具有键值 "Product":"some name"
.
完全相同名称的图像
例如url
里面的图片名称必须是这样:
let productImageref = productsValue[indexPath.row]["Product"] as? String
我怎样才能得到正确的url
?我不明白。我阅读了所有文档,据我所知,我必须使用 Firebase 的 "Download URL"。为了获取图像,我正在使用“KingFish”第 3 方库异步执行此操作。
我这样试过,但没有给我图像:
let productImageref = productsValue[indexPath.row]["nicotine"] as? String
cell!.imageView!.kf_setImageWithURL(NSURL(string: "https://firebasestorage.googleapis.com/v0/b/snuspedia.appspot.com/o/Catch%20Dry%20Eucalyptus%20White%20Mini.png?alt=media&token=68cf4b76-e35b-4868-80f3-d29872e00122")!, placeholderImage: nil)
像上面的代码一样,我可以加载图像,但我必须在每个 cell
.
上加载不同的图像
我做错了什么?欢迎任何提示。
GS 存储 URL 不是真正的 URL 您可以随时访问。只有经过身份验证才能访问它。
因此,GET HTTP 调用永远无法获取带有 GS URL 的图像。
根据我的经验,上传的图片 URL 最好保持这样:
let reference = storage.referenceForURL(Constant.Firebase.FIREBASE_STORAGE).child(imageNameWithDate())
if (picture != nil)
{
let picData = UIImageJPEGRepresentation(picture!, 0.6)
reference.putData(picData!, metadata: nil) { (metadata, error) in
if error == nil {
let link = metadata?.downloadURL()!.absoluteString
//save this link for the image URL.
}
}
我做的很对,但有点不对:D
这是非常有效的代码:
let productImageref = productsValue[indexPath.row]["Products"] as? String
FIRStorage.storage().reference().child("\(productImageref!).png").downloadURLWithCompletion({(url, error)in
if error != nil{
print(error)
}else{
(cell?.imageView)!.kf_setImageWithURL(url, placeholderImage: nil)
}
})
我正在尝试从 Firebase
存储中获取图像。我必须得到与 JSON
具有键值 "Product":"some name"
.
例如url
里面的图片名称必须是这样:
let productImageref = productsValue[indexPath.row]["Product"] as? String
我怎样才能得到正确的url
?我不明白。我阅读了所有文档,据我所知,我必须使用 Firebase 的 "Download URL"。为了获取图像,我正在使用“KingFish”第 3 方库异步执行此操作。
我这样试过,但没有给我图像:
let productImageref = productsValue[indexPath.row]["nicotine"] as? String
cell!.imageView!.kf_setImageWithURL(NSURL(string: "https://firebasestorage.googleapis.com/v0/b/snuspedia.appspot.com/o/Catch%20Dry%20Eucalyptus%20White%20Mini.png?alt=media&token=68cf4b76-e35b-4868-80f3-d29872e00122")!, placeholderImage: nil)
像上面的代码一样,我可以加载图像,但我必须在每个 cell
.
我做错了什么?欢迎任何提示。
GS 存储 URL 不是真正的 URL 您可以随时访问。只有经过身份验证才能访问它。 因此,GET HTTP 调用永远无法获取带有 GS URL 的图像。 根据我的经验,上传的图片 URL 最好保持这样:
let reference = storage.referenceForURL(Constant.Firebase.FIREBASE_STORAGE).child(imageNameWithDate())
if (picture != nil)
{
let picData = UIImageJPEGRepresentation(picture!, 0.6)
reference.putData(picData!, metadata: nil) { (metadata, error) in
if error == nil {
let link = metadata?.downloadURL()!.absoluteString
//save this link for the image URL.
}
}
我做的很对,但有点不对:D
这是非常有效的代码:
let productImageref = productsValue[indexPath.row]["Products"] as? String
FIRStorage.storage().reference().child("\(productImageref!).png").downloadURLWithCompletion({(url, error)in
if error != nil{
print(error)
}else{
(cell?.imageView)!.kf_setImageWithURL(url, placeholderImage: nil)
}
})