uploadTask(with:from:)
Creates a task that performs an HTTP request for the specified URL request object and uploads the provided data.
Declaration
func uploadTask(with request: URLRequest, from bodyData: Data) -> URLSessionUploadTaskParameters
- request:
A URL request object that provides the URL, cache policy, request type, and so on. The body stream and body data in this request object are ignored.
- bodyData:
The body data for the request.
Mentioned in
Return Value
The new session upload task.
Discussion
An HTTP upload request is any request that contains a request body, such as a POST or PUT request. Upload tasks require you to create a request object so that you can provide metadata for the upload, like HTTP request headers.
After you create the task, you must start it by calling its resume() method. The task calls methods on the session’s delegate to provide you with the upload’s progress, response metadata, response data, and so on.
See Also
Adding upload tasks to a session
Building a resumable upload server with SwiftNIOuploadTask(with:from:completionHandler:)uploadTask(with:fromFile:)uploadTask(with:fromFile:completionHandler:)uploadTask(withStreamedRequest:)uploadTask(withResumeData:)uploadTask(withResumeData:completionHandler:)URLSessionUploadTaskURLSessionDataDelegate