DocumentClient.CreateAttachmentAsync Método

Definição

Sobrecargas

CreateAttachmentAsync(String, Stream, MediaOptions, RequestOptions, CancellationToken)

Cria um Attachment com o conteúdo do fornecido mediaStream como uma operação assíncrona no serviço do Azure Cosmos DB.

CreateAttachmentAsync(Uri, Stream, MediaOptions, RequestOptions, CancellationToken)

Cria um anexo como uma operação assíncrona no serviço do Azure Cosmos DB.

CreateAttachmentAsync(String, Object, RequestOptions, CancellationToken)

Cria um anexo como uma operação assíncrona no serviço do Azure Cosmos DB.

CreateAttachmentAsync(Uri, Object, RequestOptions, CancellationToken)

Cria um anexo como uma operação assíncrona no serviço do Azure Cosmos DB.

CreateAttachmentAsync(String, Stream, MediaOptions, RequestOptions, CancellationToken)

Cria um Attachment com o conteúdo do fornecido mediaStream como uma operação assíncrona no serviço do Azure Cosmos DB.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> CreateAttachmentAsync (string attachmentsLink, System.IO.Stream mediaStream, Microsoft.Azure.Documents.Client.MediaOptions options = default, Microsoft.Azure.Documents.Client.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAttachmentAsync : string * System.IO.Stream * Microsoft.Azure.Documents.Client.MediaOptions * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.CreateAttachmentAsync : string * System.IO.Stream * Microsoft.Azure.Documents.Client.MediaOptions * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function CreateAttachmentAsync (attachmentsLink As String, mediaStream As Stream, Optional options As MediaOptions = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

Parâmetros

attachmentsLink
String

O link de anexos para o documento. Por exemplo, dbs/db_rid/colls/col_rid/docs/doc_rid/attachments/

mediaStream
Stream

o Stream da mídia de anexo.

options
MediaOptions

o MediaOptions para a solicitação.

requestOptions
RequestOptions

Opções de solicitação.

cancellationToken
CancellationToken

(Opcional) Um CancellationToken que pode ser usado por outros objetos ou threads para receber uma notificação de cancelamento.

Retornos

O objeto de tarefa que representa a resposta do serviço para a operação assíncrona.

Implementações

Exceções

Se ou attachmentsLinkmediaStream não estiver definido.

Exemplos

//This attachment could be any binary you want to attach. Like images, videos, word documents, pdfs etc. it doesn't matter
using (FileStream fileStream = new FileStream(@".\something.pdf", FileMode.Open))
{
    //Create the attachment
    Attachment attachment = await client.CreateAttachmentAsync("dbs/db_rid/colls/coll_rid/docs/doc_rid/attachments/",
                                        fileStream,
                                        new MediaOptions
                                        {
                                            ContentType = "application/pdf",
                                            Slug = "something.pdf"
                                        });
}

Confira também

Aplica-se a

CreateAttachmentAsync(Uri, Stream, MediaOptions, RequestOptions, CancellationToken)

Cria um anexo como uma operação assíncrona no serviço do Azure Cosmos DB.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> CreateAttachmentAsync (Uri documentUri, System.IO.Stream mediaStream, Microsoft.Azure.Documents.Client.MediaOptions options = default, Microsoft.Azure.Documents.Client.RequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAttachmentAsync : Uri * System.IO.Stream * Microsoft.Azure.Documents.Client.MediaOptions * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.CreateAttachmentAsync : Uri * System.IO.Stream * Microsoft.Azure.Documents.Client.MediaOptions * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function CreateAttachmentAsync (documentUri As Uri, mediaStream As Stream, Optional options As MediaOptions = Nothing, Optional requestOptions As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

Parâmetros

documentUri
Uri

o URI do documento para o qual criar um anexo.

mediaStream
Stream

o fluxo da mídia de anexo.

options
MediaOptions

as opções de mídia para a solicitação.

requestOptions
RequestOptions

As opções de solicitação para a solicitação.

cancellationToken
CancellationToken

(Opcional) CancellationToken que representa o cancelamento da solicitação.

Retornos

O objeto de tarefa que representa a resposta do serviço para a operação assíncrona.

Implementações

Aplica-se a

CreateAttachmentAsync(String, Object, RequestOptions, CancellationToken)

Cria um anexo como uma operação assíncrona no serviço do Azure Cosmos DB.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> CreateAttachmentAsync (string documentLink, object attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAttachmentAsync : string * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.CreateAttachmentAsync : string * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function CreateAttachmentAsync (documentLink As String, attachment As Object, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

Parâmetros

documentLink
String

O link do documento pai para este novo anexo. Por exemplo, dbs/db_rid/colls/col_rid/docs/doc_rid/

attachment
Object

O objeto de anexo.

options
RequestOptions

(Opcional) As opções de solicitação para a solicitação.

cancellationToken
CancellationToken

(Opcional) Um CancellationToken que pode ser usado por outros objetos ou threads para receber uma notificação de cancelamento.

Retornos

O Task objeto que representa a resposta do serviço para a operação assíncrona.

Implementações

Exemplos

O exemplo a seguir cria um novo documento e, em seguida, cria um novo anexo para esse documento

dynamic d = new
{
    id = "DOC1800243243470"
};

Document doc = await client.CreateDocumentAsync(collectionSelfLink, d);

//Create an Attachment which links to binary content stored somewhere else
//Use the MediaLink property of Attachment to set where the binary resides
//MediaLink can also point at another Attachment within Azure Cosmos DB.
Attachment a = await client.CreateAttachmentAsync(doc.SelfLink, new Attachment { Id = "foo", ContentType = "text/plain", MediaLink = "link to your media" });

//Because Attachment is a Dynamic object you can use SetPropertyValue method to any property you like
//Even if that property doesn't exist. Here we are creating two new properties on the Attachment we created above.
a.SetPropertyValue("Foo", "some value");
a.SetPropertyValue("Bar", "some value");

//Now update the Attachment object in the database to persist the new properties on the object
client.ReplaceAttachmentAsync(a);

//Let's now create another Attachment except this time we're going to use a Dynamic object instead
//of a <see cref="Microsoft.Azure.Documents.Attachment"/> as we did above.
var b = await client.CreateAttachmentAsync(doc.SelfLink, new { id = "foo", contentType = "text/plain", media="link to your media", a = 5, b = 6 });

//Now you will have a Document in your database with two attachments.

Confira também

Aplica-se a

CreateAttachmentAsync(Uri, Object, RequestOptions, CancellationToken)

Cria um anexo como uma operação assíncrona no serviço do Azure Cosmos DB.

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> CreateAttachmentAsync (Uri documentUri, object attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateAttachmentAsync : Uri * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
override this.CreateAttachmentAsync : Uri * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function CreateAttachmentAsync (documentUri As Uri, attachment As Object, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

Parâmetros

documentUri
Uri

o URI do documento para o qual criar um anexo.

attachment
Object

o objeto de anexo.

options
RequestOptions

As opções de solicitação para a solicitação.

cancellationToken
CancellationToken

(Opcional) CancellationToken que representa o cancelamento da solicitação.

Retornos

O objeto de tarefa que representa a resposta do serviço para a operação assíncrona.

Implementações

Aplica-se a