---
title: "requestData(for:options:dataReceivedHandler:completionHandler:)"
framework: photos
role: symbol
role_heading: Instance Method
path: "photos/phassetresourcemanager/requestdata(for:options:datareceivedhandler:completionhandler:)"
---

# requestData(for:options:dataReceivedHandler:completionHandler:)

Requests the underlying data for the specified asset resource, to be delivered asynchronously.

## Declaration

```swift
func requestData(for resource: PHAssetResource, options: PHAssetResourceRequestOptions?, dataReceivedHandler handler: @escaping (Data) -> Void, completionHandler: @escaping ((any Error)?) -> Void) -> PHAssetResourceDataRequestID
```

## Parameters

- `resource`: The asset resource for which to request data.
- `options`: Options specifying how Photos should handle the request and notify your app of progress. For details, see doc://com.apple.photokit/documentation/Photos/PHAssetResourceRequestOptions.
- `handler`: A block that Photos calls to provide the requested data. The block takes a single parameter:
- `completionHandler`: A block that photos calls after the request has been fulfilled or has failed. The block takes a single parameter:

## Return Value

Return Value A numeric identifier for the request. If you need to cancel the request before it completes, pass this identifier to the cancelDataRequest(_:) method.

## Discussion

Discussion When you call this method, Photos begins asynchronously reading the underlying data for the asset resource. Depending on the options you specify and the current state of the asset, Photos may download asset data from the network. While reading (or downloading) asset resource data, Photos calls your handler block at least once, progressively providing chunks of data. After reading all of the data, Photos calls your completionHandler block to indicate that the data is complete. (At this point, the complete data for the asset is the concatenation of the data parameters from all calls to your handler block.) If Photos cannot finish reading or downloading asset resource data, it calls your completionHandler block with a description of the error. Photos can also call the completionHandler block with a non-nil error when the data is complete if the user cancels downloading. note: Photos calls your handler and completionHandler blocks on an arbitrary serial queue. To update the UI in response to these events, dispatch to the main queue.

## See Also

### Requesting Resources

- [cancelDataRequest(_:)](photos/phassetresourcemanager/canceldatarequest(_:).md)
- [writeData(for:toFile:options:completionHandler:)](photos/phassetresourcemanager/writedata(for:tofile:options:completionhandler:).md)
