代码之家  ›  专栏  ›  技术社区  ›  Gowthaman M manas.abrol

Swift如何将不同文件名的图像上传到firebase?

  •  0
  • Gowthaman M manas.abrol  · 技术社区  · 6 年前

    我是新的IOS,请考虑。我的问题是,每当我上传图像,它只是取代现有的图像。

    现在我想上传唯一文件名的图像。我正在用照相机拍照。

    func uploadtofirebase(){
    
            let imagepath = UIImagePNGRepresentation(self.imagebutton.image!)
            if imagepath == nil {
                return
            }
            var strURL = "imagePickerController.png"
    
           let storage = Storage.storage()
           let storageRef = storage.reference().child("IosImages/").child(strURL)
              print("calling here successfully ")
            storageRef.putData(imagepath!, metadata:nil,completion:
                {(metadata,error) in storageRef.downloadURL(completion: { (url, error) in
    
                    if let urlText = url?.absoluteString{
                        strURL = urlText
                        print("///////////tttttttt//////// \(strURL)   ////////")
                        //completion(strURL)
                        print("passed activity")
                        self.startReceivingLocationChanges()
                    }
                })
            })
    }
    

    .child(strURL) strURL 我必须让它充满活力。我已经做了安卓,但我不能做iOS。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Jay Patel    6 年前

     func generateImageName() -> String {
        let date = Date()
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyyMMddHHmmSS"
        let result = formatter.string(from: date)
        return "\(result).png"
     }
    

    只要调用这个函数,你每次都会得到新的图像名。这也很有用,因为它包含生成的日期和时间。