put不是StorageReference的成员,它的类型值

时间:2018-06-11 18:30:26

标签: swift firebase firebase-storage

它给了我这个错误:'StorageReference'类型的值没有成员'put'

继承守则:

if let imgData = UIImageJPEGRepresentation(img, 0.2) {

        let imgUid = NSUUID().uuidString

        let metadata = StorageMetadata()

        metadata.contentType = "image/jpeg"

        Storage.storage().reference().child(imgUid).put(imgData, metadata: metadata) { (metadata, error) in

            if error != nil {

                print("did not upload img")
            } else {

                print("uploaded")

                let downloadURL = metadata?.downloadURL()?.absoluteString

                if let url = downloadURL {

                    self.setUser(img: url)
                }
            }
        }
    }

此行中出现错误:

Storage.storage().reference().child(imgUid).put(imgData, metadata: metadata) { (metadata, error) in

我根据这个错误搜索了所有其他帖子,但没有任何帮助我...我暂时没有碰到这个项目,我只知道,这可能是因为新的Firebase 5

1 个答案:

答案 0 :(得分:0)

从文档的快速浏览看,该方法现在是putData。请参阅guide to uploading datareference docs。从指南:

let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
  ...