Table of Contents

Class Attachment

Namespace
Microsoft.Azure.Documents
Assembly
Microsoft.Azure.Documents.Client.dll

Represents a document attachment in the Azure Cosmos DB service.

public class Attachment : Resource, IDynamicMetaObjectProvider
Inheritance
Attachment
Implements
Inherited Members
Extension Methods

Remarks

Each document may contain zero or more attachments containing data of arbitrary formats like images, binary or large text blobs. The Attachment class represents the Azure Cosmos DB resource used to store information about the attachment like its location and MIME content type. The payload itself ("Media") is referenced through the MediaLink property. The Attachment class is a DynamicObject and can contain any custom metadata to be persisted.

Attachments can be created as managed or unmanaged. If attachments are created as managed through Azure Cosmos DB, then it is assigned a system generated mediaLink. Azure Cosmos DB then automatically performs garbage collection on the media when parent document is deleted.

You can reuse the mediaLink property to store an external location e.g., a file share or an Azure Blob Storage URI. Azure Cosmos DB will not perform garbage collection on mediaLinks for external locations.

Constructors

Attachment()

Initializes a new instance of an Attachment class for the Azure Cosmos DB service.

public Attachment()

Properties

ContentType

Gets or sets the MIME content type of the attachment in the Azure Cosmos DB service.

public string ContentType { get; set; }

Property Value

string

The MIME content type of the attachment.

Remarks

For example, set to "text/plain" for text files, "image/jpeg" for images.

Gets or sets the media link associated with the attachment content in the Azure Cosmos DB service.

public string MediaLink { get; set; }

Property Value

string

The media link associated with the attachment content.

Azure Cosmos DB supports both managed and unmanaged attachments.