Search
 
SCRIPT & CODE EXAMPLE
 

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)")
    }
Comment

PREVIOUS NEXT
Code Example
Swift :: swift closures 
Swift :: Assign values to enum variables Swift 
Swift :: swift optionals 
Swift :: Swift Overriding Methods and Properties 
Swift :: corner radius with animation swift 
Swift :: how to read music library from iphone programmatically in swift 
Swift :: get links from string or html a tag swift 
Swift :: Example: Nested Tuple 
Swift :: swift complete print function syntax 
Swift :: swiftUI parse json from url 
Swift :: load plist swift 
Swift :: microsoft flight simulator uses which language 
Ruby :: rails get list of tables 
Ruby :: rails api only with postgress and rspec 
Ruby :: rspec check array without order 
Ruby :: get current year in ruby 
Ruby :: how to create migration with uniqueness inrails 
Ruby :: activerecord less than 
Ruby :: rails update without callback 
Ruby :: rails datatypes 
Ruby :: list ruby versions 
Ruby :: rails resources only 
Ruby :: ruby map array 
Ruby :: rails convert image to base64 
Ruby :: meaning of {} in ruby 
Ruby :: rails change resource name 
Ruby :: dynamic database connection in rails 
Ruby :: ruby deep copy 
Ruby :: ruby name parameters 
Ruby :: insert element in the middle of an array ruby 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =