top of page
  • Writer's pictureClearly Innovative

Swift with AFNetworking - AFMultipartFormData File Upload

Looked into using AlamoFire but it does not support the feature currently so I had to fallback to AFNetworking to get the needed functionality. As usual when using swift, you will need to create your bridging file and include the appropriate header files.

For the purpose of  this simeple exercise, I just included an image file in the project directory, so I am using the main bundle to get the file path for uploading. You could have integrated the camera or photo gallery to get the image, but lets keep it simple.

Next is to create the parameters for the form data as a Swift dictionary, notice the file is not included. finally inconstructingBodyWithBlock  is where we specify the file data that is to be uploaded.

Thats pretty much it and it works wonderfully when integrating with a webservice that is looking for a form submission and not a JSON object post that you often see today.

470 views0 comments


bottom of page