0

我正在尝试为 Swift 3 和 Alamofire 4 转换代码,我目前正在努力解决以下错误:

Cannot call value of non-function type '((UInt) -> Data?)!'

在这一行:

multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)

请对此案提出您的建议。我当前的代码如下。

Alamofire.upload(
    multipartFormData: { multipartFormData in
        multipartFormData.append(imageData!, withName: "image", fileName: nowString + "To" + receiverString! + ".jpg", mimeType: "image/jpg")
        for (key, value) in parameters {
            multipartFormData.append(data: value!.data(using: String.Encoding.utf8.rawValue)!, name: key)
        }
    },to:"uploadimgURL"
      encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _)                    
            upload.responseString(completionHandler: { (response) in
                debugPrint(response)
            })

        case .failure(let encodingError):
            print(encodingError)
        }
    }
)
4

1 回答 1

2

我确实看到有问题的线路存在一个问题。尝试不要像这样使用枚举的原始值:

let stringValue = value as! String
multipartFormData.append(data: stringValue.data(using: .utf8)!, name: key)
于 2016-10-31T13:10:19.643 回答