Swift3 阿拉莫菲尔4上传参数

Swift3 阿拉莫菲尔4上传参数,swift3,alamofire,Swift3,Alamofire,我正在执行以下操作以上载带有参数的PNG文件: Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")

我正在执行以下操作以上载带有参数的PNG文件:

    Alamofire.upload(
        multipartFormData: { multipartFormData in
            multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")

            // Send parameters
            multipartFormData.append((UserDefaults.standard.value(forKey: Email) as! String).data(using: .utf8)!, withName: "email")
            multipartFormData.append("png".data(using: .utf8)!, withName: "type")

        },
        to: "user/picture",
        encodingCompletion: { encodingResult in
            switch encodingResult {
            case .success(let upload, _, _):
                upload.responseJSON { response in
                    debugPrint("SUCCESS RESPONSE: \(response)")
                }
            case .failure(let encodingError):
                self.removeSpinnerFromView()
                print("ERROR RESPONSE: \(encodingError)")

            }
        }
    )
问题是,在我的服务器上,我看不到
电子邮件
类型
表单字段。我遵循了网上发布的例子。有什么我应该做的不同吗

编辑

如果我移除我放置的零件:

multipartFormData.append(UIImagePNGRepresentation(tempImage!)!, withName: "file", fileName: "picture.png", mimeType: "image/png")

然后包括参数。否则,我认为这是Alamofire4.0.1中的一个bug。

在我这方面工作正常

我正在使用以下代码:

let parameters = [
            "file_name": "swift_file.jpeg"
        ]

Alamofire.upload(multipartFormData: { (multipartFormData) in
            multipartFormData.append(UIImageJPEGRepresentation(self.photoImageView.image!, 1)!, withName: "photo_path", fileName: "swift_file.jpeg", mimeType: "image/jpeg")
            for (key, value) in parameters {
                multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
            }
            }, to:"http://sample.com/upload_img.php")
    { (result) in
        switch result {
        case .success(let upload, _, _):

            upload.uploadProgress(closure: { (progress) in
                //Print progress
            })

            upload.responseJSON { response in
                //print response.result
            }

        case .failure(let encodingError):
               //print encodingError.description
        }
    }

如果您的值是Any类型,则可以这样更改它

for (key, value) in params {
    let paramsData:Data = NSKeyedArchiver.archivedData(withRootObject: value)
    formData.append(paramsData, withName: key)
}

在参数中的for(key,value)中,值类型是否为“AnyObject”?@MicroR在我这边工作正常。这可能是后端问题。@EktaPadaliya。你能指导如何使用swift 3 alamofire 4上传图像吗。我已经完成了swift 2.3,但无法实现swift 3。请引导我。@EktaPadaliya。不,但我还需要包括标题,我怎么能add@UmaMadhavi您必须添加“导入Alamofire”。