当我将图像上传到Firebase存储时,用户照片显示为空白。我曾尝试使用Firebase指南,但它们使我如何重组此代码以解决此错误感到困惑?
contentType =“ profileImage / jpg”;名称=“ profileImage / jAKbuwI5JMZctxbQzBVJhei2EzS2”; }对象profileImage / jAKbuwI5JMZctxbQzBVJhei2EzS2不存在。完成
let StorageRef = Storage.storage().reference(forURL: "firebase.appspot.com")
let data = Data()
let storageProfileRef = StorageRef.child("profileImage/jpg")
let metadata = StorageMetadata()
metadata.contentType = "profileImage/jpg"
storageProfileRef.putData( data, metadata: metadata) { (storageMetaData, error) in
}
print(metadata)
storageProfileRef.downloadURL { (url, error) in
guard let downloadURL = url else {
if error != nil
{
print(error!.localizedDescription)
}
else
{
print(url!.absoluteString)
}
return
}
我做了一个将图像上传到Firebase存储的功能
func uploadImageToStorage()
{
let storageRef = Storage.storage().reference().child("imageName.jpg")
//Here imageData is your image's Data for Upload to storage
storageRef.putData(imageData, metadata: nil)
{(metadata, error) in
guard let metadata = metadata else
{
return
}
print(metadata)
storageRef.downloadURL { (url, error) in
if error != nil
{
print(error!.localizedDescription)
}
else
{
print(url!.absoluteString)
}
}
}
}