0

My backend server multipart/related data for images. How to handle it in my iOS client side by using Alamofire?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Bagusflyer
  • 12,675
  • 21
  • 96
  • 179

1 Answers1

0

To upload the multipart image from IOS the sample code is below:

 if let URL = try? URLRequest(url: url, method: .post, headers: nil) {
        Alamofire.upload(multipartFormData: { (multipartFormData) in
            multipartFormData.append(UIImageJPEGRepresentation(image, 0.001), withName: "file", fileName: params.imageName, mimeType: "image/jpeg")
        }, with: URL) { (result) in
            switch result {
            case .success(let upload, _, _):
                //Enter Success Code
            case .failure:
                //Enter failure Code
            }
        }

Hope that helps.

Shruti
  • 1,849
  • 1
  • 13
  • 21
  • Actually I know how to upload. But my question is how to download images served as multipart/related by my backend. – Bagusflyer Sep 17 '18 at 12:06
  • @ZhouHao have you tried using SDWebImage. this is a third party library but this helps in downloading images from url. This also download the image in parts. – Shruti Sep 18 '18 at 04:38
  • I can't download image from url directly because the backend serve the images as multipart/related data. – Bagusflyer Sep 18 '18 at 05:59