How to make multipart request using Alamofire 3.0 in Swift

Updated 26 October 2021

Save

Multipart Request

Sometimes we need to upload the multiple images to a server in a single request, for this Alamofire 3.0 provide the upload facility where we can upload ‘n’ number of images in the single request.

For this we have to follow some steps;

1: First we have to fetch all images in a single array and store all UIImage object in the array.

Ex:

var imageDataArray:NSMutableArray = []

2: Now collect all the data which you have to send like params, headers or any data

Note: don’t access the data which is on the main thread, when you are uploading the images to server because upload works on background thread only.

Ex: like fetching the value from UItextfield etc;

3: define header in ViewdidLoad()

4: Now its time to define the method :

Note:  a: imageFlagArray  -> is bool array to check the array contains UIImage data or not.

b:  self.imageDataArray[i]  -> it contains UIImage object of Images.

c: self.UPLOAD_URL – > it is base URL where we have to upload.

d: self.headers -> it is header which I have defined in viewdidload method;

Now check the proper params and header field, upload URL then try it.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


1 comments

  • anil
    i like it
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home