---
title: fileDataRepresentation()
framework: avfoundation
role: symbol
role_heading: Instance Method
path: avfoundation/avcapturephoto/filedatarepresentation()
---

# fileDataRepresentation()

Generates and returns a flat data representation of the photo and its attachments.

## Declaration

```swift
func fileDataRepresentation() -> Data?
```

## Mentioned in

Saving captured photos Capturing photos in RAW and Apple ProRAW formats Capturing photos with depth Capturing thumbnail and preview images Capturing uncompressed image data Configuring camera capture to collect a Portrait Effects matte

## Return Value

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

Discussion When you request a photo capture with the AVCapturePhotoOutput capturePhoto(with:delegate:) method, the 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.

## See Also

### Packaging data for file output

- [fileDataRepresentation(with:)](avfoundation/avcapturephoto/filedatarepresentation(with:).md)
- [AVCapturePhotoFileDataRepresentationCustomizer](avfoundation/avcapturephotofiledatarepresentationcustomizer.md)
- [cgImageRepresentation()](avfoundation/avcapturephoto/cgimagerepresentation().md)
- [previewCGImageRepresentation()](avfoundation/avcapturephoto/previewcgimagerepresentation().md)
- [fileDataRepresentation(withReplacementMetadata:replacementEmbeddedThumbnailPhotoFormat:replacementEmbeddedThumbnailPixelBuffer:replacementDepthData:)](avfoundation/avcapturephoto/filedatarepresentation(withreplacementmetadata:replacementembeddedthumbnailphotoformat:replacementembeddedthumbnailpixelbuffer:replacementdepthdata:).md)
