public static async Task <Guid> CreateBlobAsync(HttpClient httpClient, ILogger logger, ParentType blobType, BlobContent blobContent, IFormFile file) { var metadataContent = new StringContent(JsonConvert.SerializeObject(blobContent.ToCreate()), Encoding.UTF8, "application/json"); metadataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); var reader = new StreamReader(file.OpenReadStream()); var subContent = new StreamContent(reader.BaseStream); subContent.Headers.ContentType = MediaTypeHeaderValue.Parse(file.ContentType); var multipartContent = new MultipartFormDataContent("blobBoundary") { { metadataContent, "metadata" }, { subContent, "blob" } }; var response = await httpClient.PostAsync($"{blobType}s/blobs", multipartContent); var id = await GetIdFromResponse(response, logger, multipartContent.ToString()); if (id != Guid.Empty) { await FeedbackHelper.Channel.SendMessageAsync($"{blobType} blob successfully created with the ID {id}", MessageType.Info); } return(id); }
public static async Task <bool> UpdateBlobAsync(HttpClient httpClient, ILogger logger, ParentType blobType, BlobContent blobContent, IFormFile file) { var metadataContent = new StringContent(JsonConvert.SerializeObject(blobContent.ToCreate()), Encoding.UTF8, "application/json"); metadataContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); var reader = new StreamReader(file.OpenReadStream()); var subContent = new StreamContent(reader.BaseStream); subContent.Headers.ContentType = MediaTypeHeaderValue.Parse(file.ContentType); var multipartContent = new MultipartFormDataContent("blobBoundary") { { metadataContent, "metadata" }, { subContent, "blob" } }; var response = await httpClient.PatchAsync($"{blobType}s/blobs/{blobContent.Id}", multipartContent); return(await IsSuccessCall(response, logger)); }