<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionTaskDelegate/urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLSessionTaskDelegate(im)URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:"
  },
  "title" : "urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)"
}
-->

# urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)

Periodically informs the delegate of the progress of sending body content to the server.

```
optional func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64)
```

## Parameters

`session`

The session containing the data task.

`task`

The data task.

`bytesSent`

The number of bytes sent since the last time this delegate method was called.

`totalBytesSent`

The total number of bytes sent so far.

`totalBytesExpectedToSend`

The expected length of the body data. The URL loading system can determine the length of the upload data in three ways:

- From the length of the `NSData` object provided as the upload body.
- From the length of the file on disk provided as the upload body of an upload task (*not* a download task).
- From the `Content-Length` in the request object, if you explicitly set it.

    Otherwise, the value is [`NSURLSessionTransferSizeUnknown`](/documentation/Foundation/NSURLSessionTransferSizeUnknown)     (    `-1`    ) if you provided a stream or body data object, or zero (    `0`    ) if you did not.

## Discussion

The `totalBytesSent` and `totalBytesExpectedToSend` parameters are also available as [`URLSessionTask`](/documentation/Foundation/URLSessionTask) properties [`countOfBytesSent`](/documentation/Foundation/URLSessionTask/countOfBytesSent) and [`countOfBytesExpectedToSend`](/documentation/Foundation/URLSessionTask/countOfBytesExpectedToSend). Or, since [`URLSessionTask`](/documentation/Foundation/URLSessionTask) supports [`ProgressReporting`](/documentation/Foundation/ProgressReporting), you can use the task’s [`progress`](/documentation/Foundation/URLSessionTask/progress) property instead, which may be more convenient.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)