Issue in uploading image with parameters using Alamofire

58 Views Asked by At
 let URL_str = API.sendImage
    let image = UIImage(named: "photo.jpg")
    let imagData = UIImageJPEGRepresentation(image!, 1)!
    print(imagData)
    let parameters : Parameters = [
        "phone" :  USERDEFAULT.getPhoneNo(),
        "password" : USERDEFAULT.getPassword(),
        "friend_uid" : "01206921-71a5-4e14-8084-62560022c30c59e22b245278483f4c67244b-1698492849",
        "conversation_id" : "3c1de3f388a5450e7c9d9c4bf6f18ec1",
    ]


    Alamofire.upload(multipartFormData:
        { (multipartFormData) in

            multipartFormData.append(imagData, withName: "file", fileName: "testImg.jpg", mimeType: "image/jpg")
            for (key, value) in parameters
            {
                multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
            }
        }, to: URL_str)
            { (result) in
                switch result
                {
                case .success(let upload, _, _):

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

                })
                upload.responseJSON { response in
                print(response.description)
            }

                case .failure(let encodingError):
                print(encodingError.localizedDescription)
                break
        }
    }

This is my complete code, how i upload image with parameters. But issue is that Image Data before uploading: 272707 bytes & Image Data on Server: 0 bytes. Kindly someone help me. What am i doing wrong? And Thanks in advance.

0

There are 0 best solutions below