Instance Method

uploadTaskWithStreamedRequest:

Creates a task that performs an HTTP request for uploading data based on the specified URL request.

Declaration

- (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request;

Parameters

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, and the session calls its delegate’s URLSession:task:needNewBodyStream: method to provide the body data.

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 provide a request object so that you can provide metadata for the upload, such as 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. The session’s delegate must have a URLSession:task:needNewBodyStream: method that provides the body data to upload.

See Also

Adding Upload Tasks to a Session

uploadTaskWithRequest:fromData:

Creates a task that performs an HTTP request for the specified URL request object and uploads the provided data.

uploadTaskWithRequest:fromData:completionHandler:

Creates a task that performs an HTTP request for the specified URL request object, uploads the provided data, and calls a handler upon completion.

uploadTaskWithRequest:fromFile:

Creates a task that performs an HTTP request for uploading the specified file.

uploadTaskWithRequest:fromFile:completionHandler:

Creates a task that performs an HTTP request for uploading the specified file, then calls a handler upon completion.

NSURLSessionUploadTask

A URL session task that uploads data to the network in a request body.

NSURLSessionDataDelegate

A protocol defining methods that NSURLSession instances call on their delegates to handle task-level events specific to data and upload tasks.