-
-
Save MoimHossain/6c5abe056399185f27b7d9b48fe89613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<bool> CreateFileAsync(string filesystem, string path, | |
string fileName, Stream stream) | |
{ | |
var operationResult = await this.CreateEmptyFileAsync(filesystem, path, fileName); | |
if (operationResult) | |
{ | |
var tokenInfo = await tokenProvider.GetAccessTokenV2EndpointAsync(); | |
var headers = Statics.Http.DefaultRequestHeaders; | |
headers.Clear(); | |
headers.Add("Authorization", $"Bearer {tokenInfo.access_token}"); | |
headers.Add(API_VERSION_HEADER_NAME, API_VERSION_HEADER_VALUE); | |
using (var streamContent = new StreamContent(stream)) | |
{ | |
var resourceUrl = $"{baseUri}{filesystem}{path}{fileName}?action=append&timeout={this.Timeout}&position=0"; | |
var msg = new HttpRequestMessage(new HttpMethod("PATCH"), resourceUrl); | |
msg.Content = streamContent; | |
var response = await Statics.Http.SendAsync(msg); | |
//flush the buffer to commit the file | |
var flushUrl = $"{baseUri}{filesystem}{path}{fileName}?action=flush&timeout={this.Timeout}&position={msg.Content.Headers.ContentLength}"; | |
var flushMsg = new HttpRequestMessage(new HttpMethod("PATCH"), flushUrl); | |
response = await Statics.Http.SendAsync(flushMsg); | |
return response.IsSuccessStatusCode; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment