修正Bug日
let bookItemRef = self.ref!.child(values.booktitle.lowercased())
let storageImageRef = Storage.storage().reference().child("BookRentImage").child("\(values.booktitle).jpg")
let uploadTask = storageImageRef.putData(self.ImageData!,metadata:nil){(data,error) in
if error != nil{
print(error.localizedDescription)
return
}
// KVO应用
uploadTask.observe(.success, handler:{(snapshot) in
// 下载刚刚上传图片的URL
storageImageRef.downloadRef{(url,error) in
// 要先让error 被指派为error,才能使用error
if let error = error{
print("失败",error.localizedDescription)
}else{
// absoluteString完整的网域名称
if let imageFileURL = url?.absoluteString{
// 确认是否为正确的网址
print("photoImageUploadSuccess:",imageFileURL)
}
// 新增bookImage的url上去,因为如果按下上传 要传url要等到上传结束
bookItemRef.child(values.booktitle).setValue(bookItem.ImagetoDictionary(),withCompletionBlock:{ (error,ref) in
if error = nil{
let alertController = UIAlertControler(title:"Upload Image Success!",message:"Congradulation",preferredStyle: .alert)
let alertAction = UIAlertAction(title:"OK", style:.cancel, handler:nil)
alertController.addAction(alertAction)
self.present(alertControler,animated:true, completion: nil)
}
})
bookItem = Book(booktitle: values.booktitle, bookauthors: values.bookauthors, bookISBN: values.bookISBN, bookimage: self.uploadURL)
// 新增Book的等等资训
bookItemRef.setValue(bookItem.toDictionary(),withCompletionBlock:{ (error,ref) in
if error == nil {
let alertController = UIAlertController(title: "Upload Success", message: "Congradulation", preferredStyle: .alert)
let alertAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(alertAction)
self.present(alertController, animated: true, completion: nil)
}})
absoluteString
参考网址
使用Firebase Storage、Firebase Realtime Database上传与下载图片 Swift5.3,Xcode 12,iOS 14
Download files with Cloud Storage on iOS | Firebase
<<: 30天打造品牌特色电商网站 Day.16 微互动设计按钮实作(2)
todos: 还在出去玩,之後补上演算法 pesudocode + comments 8.2 提到的...
一、前言 经营部落格,会是一个长期的网路事业,在初期有许多部分我认为就应该思考好,在整个经营路上才...
利用 provide & inject 机制,父元件当作所有其子元件的 provider,无...
大家好,我是乌木白,之前在自我介绍时!有和大家说过我目前是一个学生,平常也是需要打工,所以在一天之...
来练习帮 Google 文件增加一点内容吧。 今日要点: 》Document Service 文件...