通过Alamofire发布请求Multipartdata Swift将图像上传到服务器

时间:2020-11-08 08:02:27

标签: ios swift alamofire

我正在尝试将图像上传到服务器,但是收到如下所示的错误。这是我的代码:

        Alamofire.upload(multipartFormData: { multipartFormData in
            //Parameter for Upload files
            multipartFormData.append(imgData, withName: "file",fileName: "furkan.png" , mimeType: "image/png")
            
        }, usingThreshold:UInt64.init(),
           to: "http://192.168.80.21:8800/api/v1/upload/uploadfile", //URL Here
            method: .post,
            headers: headers, //pass header dictionary here
            encodingCompletion: { (result) in
                
                switch result {
                case .success(let upload, _, _):
                    print("the status code is :")
                    
                    upload.uploadProgress(closure: { (progress) in
                        print("something")
                    })
                    
                    upload.responseJSON { response in
                        print("the resopnse code is : \(String(describing: response.response?.statusCode))")
                        print("the response is : \(response)")
                    }
                    break
                case .failure(let encodingError):
                    print("the error is  : \(encodingError.localizedDescription)")
                    break
                }
        })
    }

但是我遇到这样的错误:

失败:responseSerializationFailed(原因:Alamofire.AFError.ResponseSerializationFailureReason.jsonSerializationFailed(错误:Error Domain = NSCocoaErrorDomain Code = 3840“字符0周围的值无效。” UserInfo = {NSDebugDescription =字符0周围的值无效。}))

0 个答案:

没有答案