<!--
{
  "availability" : [
    "iOS: 11.0.0 - 12.0.0",
    "iPadOS: 11.0.0 - 12.0.0",
    "macCatalyst: 13.1.0 - 13.1.0"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCapturePhoto/fileDataRepresentation(withReplacementMetadata:replacementEmbeddedThumbnailPhotoFormat:replacementEmbeddedThumbnailPixelBuffer:replacementDepthData:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCapturePhoto(im)fileDataRepresentationWithReplacementMetadata:replacementEmbeddedThumbnailPhotoFormat:replacementEmbeddedThumbnailPixelBuffer:replacementDepthData:"
  },
  "title" : "fileDataRepresentation(withReplacementMetadata:replacementEmbeddedThumbnailPhotoFormat:replacementEmbeddedThumbnailPixelBuffer:replacementDepthData:)"
}
-->

# fileDataRepresentation(withReplacementMetadata:replacementEmbeddedThumbnailPhotoFormat:replacementEmbeddedThumbnailPixelBuffer:replacementDepthData:)

Generates and returns a flat data representation of the photo using the specified replacements for some or all of its attachments.

```
func fileDataRepresentation(withReplacementMetadata replacementMetadata: [String : Any]?, replacementEmbeddedThumbnailPhotoFormat: [String : Any]?, replacementEmbeddedThumbnailPixelBuffer: CVPixelBuffer?, replacementDepthData: AVDepthData?) -> Data?
```

## Parameters

`replacementMetadata`

A dictionary (see `CGImageProperties` for possible keys and values) containing metadata to embed in the output file data.

    To preserve existing metadata from the photo capture, pass this [`AVCapturePhoto`](/documentation/AVFoundation/AVCapturePhoto)     object’s [`metadata`](/documentation/AVFoundation/AVCapturePhoto/metadata)     dictionary. To discard metadata, pass     `nil`    .

`replacementEmbeddedThumbnailPhotoFormat`

A dictionary (see Video Settings Dictionaries for possible keys and values) specifying the data format for a thumbnail preview image to embed in the output file data.

    To preserve the existing thumbnail image from the photo capture, pass this [`AVCapturePhoto`](/documentation/AVFoundation/AVCapturePhoto)     object’s [`embeddedThumbnailPhotoFormat`](/documentation/AVFoundation/AVCapturePhoto/embeddedThumbnailPhotoFormat)     dictionary. To discard the thumbnail, pass     `nil`    . (This parameter’s value must be consistent with that of the     `replacementEmbeddedThumbnailPixelBuffer`     parameter.)

`replacementEmbeddedThumbnailPixelBuffer`

A pixel buffer containing a source image to be encoded to the file as the replacement thumbnail image.

    To preserve the existing thumbnail image from the photo capture, pass     `nil`     for this parameter but pass this [`AVCapturePhoto`](/documentation/AVFoundation/AVCapturePhoto)     object’s [`embeddedThumbnailPhotoFormat`](/documentation/AVFoundation/AVCapturePhoto/embeddedThumbnailPhotoFormat)     dictionary for the     `replacementEmbeddedThumbnailPhotoFormat`     parameter.

    To discard the thumbnail, pass     `nil`     for both     `replacementEmbeddedThumbnail`     parameters.

`replacementDepthData`

Replacement depth data to embed in the output file data.

    To preserve the existing depth data from the photo capture (if any), pass this [`AVCapturePhoto`](/documentation/AVFoundation/AVCapturePhoto)     object’s [`depthData`](/documentation/AVFoundation/AVCapturePhoto/depthData)     object. To discard depth data, pass     `nil`    .

## Return Value

Data appropriate for writing to a file of the type specified when requesting photo capture, or `nil` if the photo and attachment data cannot be flattened.

## Discussion

When you request a photo capture with the [`AVCapturePhotoOutput`](/documentation/AVFoundation/AVCapturePhotoOutput) [`capturePhoto(with:delegate:)`](/documentation/AVFoundation/AVCapturePhotoOutput/capturePhoto(with:delegate:)) method, the [`AVCapturePhotoSettings`](/documentation/AVFoundation/AVCapturePhotoSettings) object you provide specifies image data formats (such as JPEG and HEVC) and container file formats (such as JFIF and HEIF) for the resulting image file. Calling this method formats and packages the image pixel buffer, along with metadata and other attachments created during capture (such as preview photos and depth maps), into data appropriate for writing to a file of that type.

This method is equivalent to the [`fileDataRepresentation()`](/documentation/AVFoundation/AVCapturePhoto/fileDataRepresentation()) method, but allows you to replace attachments (metadata, preview thumbnail, or depth data) captured along with the photo with alternative data.

---

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)