/// <summary> /// Put Range Request /// </summary> /// <returns></returns> public async Task PutRangeAsync(Uri storageUri, byte[] bytes, int startBytes = 0, string writeMode = "Update") { if (string.IsNullOrEmpty(storageUri.Query) || !storageUri.Query.Contains("comp=range")) { throw new Exception("Missing Query String comp=range"); } using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, storageUri)) { httpRequestMessage.Content = new ByteArrayContent(bytes); var contentlength = httpRequestMessage.Content.Headers.ContentLength - 1; var now = DateTime.UtcNow; SetDefaultHeaders(httpRequestMessage, now); httpRequestMessage.Headers.Add("x-ms-range", $"bytes={startBytes}-{contentlength.ToString()}"); httpRequestMessage.Headers.Add("x-ms-write", writeMode); // Add the authorization header. httpRequestMessage.Headers.Authorization = AzureStorageAuthenticationHelper.GetAuthorizationHeader( _accoutName, _accessKey, now, httpRequestMessage); await SendAndTraceOnErrorAsync(httpRequestMessage, storageUri); } }
public async Task CreateFileAsync(Uri storageUri) { //Instantiate the request message with a empty payload. using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, storageUri) { Content = new StringContent("") }) { var now = DateTime.UtcNow; SetDefaultHeaders(httpRequestMessage, now); // Required. This header specifies the maximum size for the file, up to 1 TiB. httpRequestMessage.Headers.Add("x-ms-content-length", "200"); httpRequestMessage.Headers.Add("x-ms-type", "file"); // If you need any additional headers, add them here before creating // the authorization header. // Add the authorization header. httpRequestMessage.Headers.Authorization = AzureStorageAuthenticationHelper.GetAuthorizationHeader( _accoutName, _accessKey, now, httpRequestMessage); // Send the request. await SendAndTraceOnErrorAsync(httpRequestMessage, storageUri); } }