Skip to content

Commit ba4a9e7

Browse files
committed
also allow uploading from Stream
1 parent db83631 commit ba4a9e7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Src/Notion.Client/RestClient/RestClient.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,20 @@ public async Task DeleteAsync(
9393
}
9494

9595
public async Task<UploadResponse> Upload(string filePath, JsonSerializerSettings serializerSettings = null)
96+
{
97+
var fileStream = File.OpenRead(filePath);
98+
return await Upload(fileStream, Path.GetFileName(filePath), serializerSettings);
99+
}
100+
101+
public async Task<UploadResponse> Upload(Stream stream, string filename, JsonSerializerSettings serializerSettings = null)
96102
{
97103
var response = await this.PostAsync<UploadResponse>("https://api.notion.com/v1/file_uploads",
98104
new UploadRequest {Mode = "single_part"});
99105

100106
using (var formData = new MultipartFormDataContent())
101107
{
102-
var fileStream = File.OpenRead(filePath);
103-
var fileContent = new StreamContent(fileStream);
104-
formData.Add(fileContent, "file", Path.GetFileName(filePath));
108+
var fileContent = new StreamContent(stream);
109+
formData.Add(fileContent, "file", filename);
105110

106111
var uploadResponse = await this.SendAsync(response.UploadUrl, HttpMethod.Post, attachContent: message =>
107112
{

0 commit comments

Comments
 (0)