Swift 如何从firebase存储获取现有映像的下载URL
我将一个图像推送到firebase存储,通过使用Resize Images Extension,我可以得到一个大小相同的图像名加上_240x320的图像。为了让你明白,我得到了原始图像的下载URL,但我不明白为什么我不能得到大小调整后图像的下载URL。这是我的密码:Swift 如何从firebase存储获取现有映像的下载URL,swift,firebase,firebase-storage,Swift,Firebase,Firebase Storage,我将一个图像推送到firebase存储,通过使用Resize Images Extension,我可以得到一个大小相同的图像名加上_240x320的图像。为了让你明白,我得到了原始图像的下载URL,但我不明白为什么我不能得到大小调整后图像的下载URL。这是我的密码: func storeImageInFirebase(){ let storeageRef = Storage.storage().reference() let imageName = UUID().uuidString
func storeImageInFirebase(){
let storeageRef = Storage.storage().reference()
let imageName = UUID().uuidString //+ ".jpg"
let imagesReference = storeageRef.child("images").child(imageName + ".jpg")
let imageData = self.imgView.image!.pngData()
let metaData = StorageMetadata()
var imageName2 = imageName //+ "_240x320.jpg"
let imagesReference2 = storeageRef.child("images").child(imageName2 + "_240x320.jpg")
metaData.contentType = "image/jpg"
imagesReference.putData(imageData!, metadata: metaData){ (metadate, error)
in
guard metadate != nil else{
print("Error: \(String(describing: error?.localizedDescription))")
return
}
// Fetch the download URL
imagesReference.downloadURL(completion: {(url, error)
in
if error != nil {
print("Faild to download url:", error!)
return
}else{
// show the url in real database
print("resized image url ..... \(url?.absoluteString)")
var theUsedURL = self.imgURL = (url?.absoluteString)!
self.sendDataToFirebase()
}
})
// Fetch the download URL
imagesReference2.downloadURL(completion: {(url, error)
in
if error != nil {
print("Faild to download url:", error!)
return
}else{
// show the url in real database
print("resized image url ..... \(url?.absoluteString)")
self.imgURL2 = (url?.absoluteString)!
self.sendDataToFirebase()
}
})
}
}
我写了两个图像引用,一个用于原始图像,另一个用于调整大小的图像。我能够获得原始图像,但我下载url时出错,并且对于已调整大小的图像,该图像不存在,我可以在Firebase存储中看到该图像。我试图在一周内解决这个问题,我将感谢任何帮助。上传的数据来自imageData per
let imageData=self.imgView.image!。pngData()
然后是imagesReference.putData(imageData!
)。您似乎没有创建image2(缩小大小的那一个)也不上传代码中的任何地方,因此您将没有下载URL。您能澄清问题所在吗?@Jay我正在使用firebase Resize Images Extension,在默认情况下,当我上传图像时,在原始图像旁边的存储中会有一个Resize图像,因此无需输入数据。我想要的是获得下载URL以进行重新设置大小图像不是原始图像。我很抱歉。第二张当然不会打印,因为有一个错误。我相信这可能是一个令牌问题。有一个已经存在了一段时间,可能有一个修复方法我解决了令牌问题,没有任何更改@JayCan你可以包括Firebase控制台->存储的屏幕截图,显示这两个文件吗?还有,请保留注释已清理,您可以删除注释中包含的错误,因为它们现在已在问题中