Multipage POST with Alamofire

I want to query my Rails server using Alamofire in Swift. I have a simple object that I would like to serialize, as well as some images that I would like to add as multi-coded data.

On my side of the rails, it's just like a request:

post :create, object: parameters, files: ['file1', 'file2'], format: :json

What is the most elegant way to do this with Alamofire?

+4
source share
2 answers

I haven't dug far into the Alamo fire yet, but reading the documentation makes me believe that it is not supported in Alamo Fire at this time. Specifically, the end of the document under the heading "When should I use AFNetworking":

Use AFNetworking for any of the following actions:

  • UIKit, UIImageView
  • TLS AFSecurityManager
  • , NSOperation NSURLConnection, AFURLConnectionOperation
  • AFNetworkReachabilityManager
  • HTTP- AFHTTPRequestSerializer
+3

,

Swift 3

MultiPartFormdata​​strong >

Alamofire.upload(multipartFormData: { (multipartFormData) in
        multipartFormData.append(UIImageJPEGRepresentation(self.Imgprofile.image!, 1)!, withName: "Prescription", fileName: "Profile_Image.jpeg", mimeType: "image/jpeg")
    }, to:"Your URL Here")
    { (result) in
        switch result {
        case .success(let upload, _, _):
            print(result)

            upload.uploadProgress(closure: { (progress) in
                print(progress)
            })

            upload.responseJSON { response in
                //print response.result
                print(response);
            }

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

0

All Articles