Skip to content

Instantly share code, notes, and snippets.

@kimipeng
Created September 17, 2018 10:25
Show Gist options
  • Select an option

  • Save kimipeng/c8550d8ff8c27041a83f7edf2defc546 to your computer and use it in GitHub Desktop.

Select an option

Save kimipeng/c8550d8ff8c27041a83f7edf2defc546 to your computer and use it in GitHub Desktop.
Alamofire Upload request
// Alamofire 4 - Simple with URL request
Alamofire.upload(fileURL, with: urlRequest).validate().responseData { response in
debugPrint(response)
}
/**************************************************************************************************************/
// Alamofire 4 - - Complex with URL string
Alamofire.upload(fileURL, to: urlString, method: .put)
.uploadProgress(queue: DispatchQueue.global(qos: .utility)) { progress in
print("Upload Progress: \(progress.fractionCompleted)")
}
.downloadProgress { progress in // called on main queue by default
print("Download Progress: \(progress.fractionCompleted)")
}
.validate { request, response, data in
// Custom evaluation closure now includes data (allows you to parse data to dig out error messages if necessary)
return .success
}
.responseJSON { response in
debugPrint(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment