Skip to content

Instantly share code, notes, and snippets.


MoimHossain/CreateFile.cs Secret

Created Sep 19, 2019
What would you like to do?
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.Add("Authorization", $"Bearer {tokenInfo.access_token}");
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