Ios 通过Almofire上载图像时失败

Ios 通过Almofire上载图像时失败,ios,swift3,alamofire,multipartform-data,Ios,Swift3,Alamofire,Multipartform Data,我正在上传多部分表单数据中的图像,但没有成功,因为它抛出了一个错误。但我尝试在邮递员它成功了。我不知道我在哪里做了一个错误。我附上了邮递员上传响应的屏幕截图。请检查它,我正在使用Almofire进行响应 func uploadimages() { let url = ServiceUrl.Base + "ShopRegistration/ShopPicture" print("URL === > \(url)") print(self.imgData?.cou

我正在上传多部分表单数据中的图像,但没有成功,因为它抛出了一个错误。但我尝试在邮递员它成功了。我不知道我在哪里做了一个错误。我附上了邮递员上传响应的屏幕截图。请检查它,我正在使用Almofire进行响应

 func uploadimages() {

    let url = ServiceUrl.Base + "ShopRegistration/ShopPicture"
    print("URL  === > \(url)")
    print(self.imgData?.count)
    var token :String = ""
    if let strToken = Preference.GetString(key: UserDefaultsKey.Token) {
        token = strToken
    }
    var RequestDist : NSDictionary = NSDictionary()
    RequestDist = ["ShopId": "\(Preference.GetInteger(key: UserDefaultsKey.ShopID))"]
        as NSDictionary;
    print(RequestDist)
    if(Reachability.isConnectedToNetwork())
    {
        Alamofire.upload(multipartFormData: { (multipartFormData) in
            if self.imgData != nil && (self.imgData?.count)! > 0 {
                for dataImg in (self.imgData)! {
                    //shopImage
                    multipartFormData.append(dataImg, withName: "shopImage", fileName: "uploaded_file.jpeg", mimeType: "image/jpeg")
                }
            }
            for (key, value) in  RequestDist {
                multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key as! String )
            }
            print("Request ===>>> /n \(multipartFormData.contentType)")
        }, to:url,headers :["authToken" : token])
        { (result) in
            switch result {
            case .success(let upload, _, _):
                upload.uploadProgress(closure: { (Progress) in
                    print("\n")
                    print(Progress.fractionCompleted)
                })
                upload.responseJSON { response in
                  if(response.result.isSuccess){
                    print("\n\n")
                    print("\(response.result.isSuccess)")
                    print("\n\n")
                    print(response.result)
                    print("\n\n")
                    print(response)
                    print("\n\n")
appDelegate.window?.rootViewController?.view.makeToast(message: "Images added sucessfully")
let datastring = NSString(data:response.data!, encoding:String.Encoding.utf8.rawValue) as String?
print("Response:::>>>> \(String(describing: datastring))")


if let intShopID : Int = Preference.GetInteger(key: UserDefaultsKey.ShopID) {
                            self.getShopImagesCall(intshopID: intShopID)
                        }

                    }else{
                        appDelegate.window?.rootViewController?.view.makeToast(message: AppMessage.getErrorInResponse)
                    }
                }
            case .failure(let encodingError):
                appDelegate.window?.rootViewController?.view.makeToast(message: AppMessage.getErrorInResponse)
                break
            }
        }
    }
}

用于
JPEG
网络图像使用
让imageData=UIImageJPEGRepresentation(img,0.5)
并在正文处
multipartFormData.append(dataImg,名称:“shopImage”,文件名:“upload\u file.jpeg”,mimeType:“image/jpeg”)

对于
PNG
图像
let image=UIImagePNGRepresentation(pickedImage)

multipartFormData.append(dataImg,名称:“shopImage”,文件名:“uploaded\u file.png”,mimeType:“image/png”)

“它抛出了一个错误。”一个错误?什么错误?@Abhiram这是什么
Data
UIImage
?@NeelBhasin Data尝试这样获取
Data
让imageData=UIImageJPEGRepresentation(img,0.5)
这里
img
是您的
UIImage
@NeelBhasin让image=UIImagePNGRepresentation(PickeImage)作为NSData吗?我在用这条线