ios - multipart/form-data using alamofire -


i making .post api call , need use multipart/form-data. know how make call using json not familiar multipart/form-data. using json, super easy call. create type parameters:

var parameters:parameters = [:] parameters["username"] = emailtextfield.text! parameters["password"] = passwordtextfield.text!  alamofire.request(url, method: .post, parameters: parameters, encoding: jsonencoding.default, headers: headers).responsejson { (response) in     //code here  } 

how write using form data. easiest way this? don't need upload files or anything. ever doing making calls extremely simple items above. cleanest way using form data. sure extremely basic question , looked around on stack overflow see being used more advanced call files. want know how in simplest way possible replacement json calls.

example docs:

alamofire.upload(     multipartformdata: { multipartformdata in         multipartformdata.append(unicornimageurl, withname: "unicorn")         multipartformdata.append(rainbowimageurl, withname: "rainbow")     },     to: "https://httpbin.org/post",     encodingcompletion: { encodingresult in         switch encodingresult {         case .success(let upload, _, _):             upload.responsejson { response in                 debugprint(response)             }         case .failure(let encodingerror):             print(encodingerror)         }     } ) 

the method's full description (if need set headers. source):

/// encodes `multipartformdata` using `encodingmemorythreshold` default `sessionmanager` , calls /// `encodingcompletion` new `uploadrequest` using `url`, `method` , `headers`. /// /// important understand memory implications of uploading `multipartformdata`. if cummulative /// payload small, encoding data in-memory , directly uploading server far /// efficient approach. however, if payload large, encoding data in-memory cause app /// terminated. larger payloads must first written disk using input , output streams keep memory /// footprint low, data can uploaded stream resulting file. streaming disk must /// used larger payloads such video content. /// /// `encodingmemorythreshold` parameter allows alamofire automatically determine whether encode in-memory /// or stream disk. if content length of `multipartformdata` below `encodingmemorythreshold`, /// encoding takes place in-memory. if content length exceeds threshold, data streamed disk /// during encoding process. result uploaded data or stream depending on encoding /// technique used. /// /// - parameter multipartformdata:       closure used append body parts `multipartformdata`. /// - parameter encodingmemorythreshold: encoding memory threshold in bytes. ///                                      `multipartformdataencodingmemorythreshold` default. /// - parameter url:                     url. /// - parameter method:                  http method. `.post` default. /// - parameter headers:                 http headers. `nil` default. /// - parameter encodingcompletion:      closure called when `multipartformdata` encoding complete. public func upload(     multipartformdata: @escaping (multipartformdata) -> void,     usingthreshold encodingmemorythreshold: uint64 = sessionmanager.multipartformdataencodingmemorythreshold,     url: urlconvertible,     method: httpmethod = .post,     headers: httpheaders? = nil,     encodingcompletion: ((sessionmanager.multipartformdataencodingresult) -> void)?) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -