in libraries/Streaming/StreamingConversations.cs [230:270]
public async Task<ResourceResponse> UploadAttachmentsAsync(string conversationId, string userId, CancellationToken cancellationToken = default(CancellationToken), params AttachmentStream[] attachmentStreams)
{
if (SocketClient == null)
{
throw new InvalidOperationException("Connection is not opened.");
}
if (attachmentStreams == null || attachmentStreams.Length == 0)
{
throw new InvalidOperationException("Cannot send attachment streams, because no attachments were supplied.");
}
var request = new StreamingRequest()
{
Verb = "PUT",
Path = $"/v3/directline/conversations/{conversationId}/users/{userId}/upload"
};
foreach (var stream in attachmentStreams)
{
var contentStream = new StreamContent(stream.ContentStream);
contentStream.Headers.TryAddWithoutValidation(HeaderNames.ContentType, stream.ContentType);
request.AddStream(contentStream);
}
var response = await SocketClient.SendAsync(request).ConfigureAwait(false);
if (response.StatusCode != 200)
{
var body = await response.ReadBodyAsStringAsync().ConfigureAwait(false);
var ex = new OperationException(
$"Operation returned an invalid status code '{response.StatusCode}'",
response.StatusCode,
body);
throw ex;
}
var resourceResponse = await response.ReadBodyAsJsonAsync<ResourceResponse>().ConfigureAwait(false);
return resourceResponse;
}