Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

Alamofire upload multiple image with parameters swift 5 site:stackoverflow.com

let baseUrl = "your URL"
    let fullUrl = baseUrl + strUrl
    var headers : HTTPHeaders = HTTPHeaders(["Content-type" : "multipart/form-data"])
    if let header = header{
        headers = header
    }
    
    guard let url = try? URLRequest(url: fullUrl, method: .post, headers: headers) else {return}
    AF.upload(multipartFormData: { (multipartData) in
        
        for i in 0 ..< arrImage.count{
            if let imageData = arrImage[i].pngData(){
                let mediaName = "media(i + 1)"
                multipartData.append(imageData, withName:mediaName, fileName: "(Date().timeIntervalSince1970).jpg", mimeType: "file")
            }
        }
      for (key, value) in parameter {
            multipartData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
        }
    }, to: url).responseJSON(queue: .main, options: .allowFragments) { (response) in
        switch response.result{
        case .success(let value):
            print("Json: (value)")
        case .failure(let error):
            print("Error: (error.localizedDescription)")
        }
    }.uploadProgress { (progress) in
        print("Progress: (progress.fractionCompleted)")
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Alamofire #upload #multiple #image #parameters #swift
ADD COMMENT
Topic
Name
8+1 =