Swift 3 Alamofire multipart upload

后端 未结 4 599
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 12:21

Thanks to migration to Swift 3, I find it difficult to compile my project that uses Alamofire.

The problem occurs when uploading multipartFormData:

A         


        
4条回答
  •  庸人自扰
    2020-12-13 13:04

    For example, using Alamofire 4.0.0 in Swift 3:

    (make sure you are 4.0.0 ready as it looks like you haven't updated your Alamofire yet)

    Alamofire.upload(multipartFormData: { (multipartFormData) in
            // code
        }, to: URL, encodingCompletion: { (result) in
            // code
        })
    

    or

    Alamofire.upload(multipartFormData: { (multipartFormData) in
            // code
        }, with: URL, encodingCompletion: { (result) in
            // code
        })
    

    So headers need to be passed by URL request:

    let URL = try! URLRequest(url: "http://example.com", method: .get, headers: headers)
    

提交回复
热议问题