view raw
Welcome King III Welcome King III - 6 months ago 79
iOS Question

Alamofire 4 swift 3 Uploading MultipartFormData with header not posting

I'm having a problem with my code and the new Alamofire 4 have searched the web for examples - no luck. My code skips the post method it's not calling to the URL:

multipartFormData in
multipartFormData.append(tempUrl, withName: self.path)},
headers: Oauthdata.uplodHeader ,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let upload, _, _):
upload.responseJSON { response in
case .failure(let encodingError):
})} catch {
print("Somethings not right")


Try the approach using RequestAdapter protocol, mentioned in the docs:

class AccessTokenAdapter: RequestAdapter {
    private let accessToken: String

    init(accessToken: String) {
        self.accessToken = accessToken

    func adapt(_ urlRequest: URLRequest) throws -> URLRequest {
        var urlRequest = urlRequest
        urlRequest.setValue("Bearer " + accessToken, forHTTPHeaderField: "Authorization")
        return urlRequest

class HTTPClient {

    func setupHeader(with authToken: String) {
        let sessionManager = SessionManager()
        sessionManager.adapter = AccessTokenAdapter(accessToken: authToken)

Where HTTPClient is the class where you are performing this setup...