Skip to content

Fix file upload filenames not being set, allow setting MIME type#62

Merged
olsh merged 5 commits into
olsh:masterfrom
zotanmew:fix/upload-file-metadata
Oct 22, 2025
Merged

Fix file upload filenames not being set, allow setting MIME type#62
olsh merged 5 commits into
olsh:masterfrom
zotanmew:fix/upload-file-metadata

Conversation

@zotanmew
Copy link
Copy Markdown
Contributor

This fixes uploaded files not getting the correct file_name set, and allows setting the MIME type (so that e.g. image thumbnails are generated as appropriate).

Comment thread src/Todoist.Net/Services/UploadService.cs Outdated
Comment thread src/Todoist.Net/Services/UploadService.cs Outdated
@olsh
Copy link
Copy Markdown
Owner

olsh commented Jan 29, 2025

Thank you for the contribution.

@zotanmew zotanmew requested a review from olsh January 29, 2025 12:46
@sonarqubecloud
Copy link
Copy Markdown

@olsh
Copy link
Copy Markdown
Owner

olsh commented Feb 3, 2025

Well, after some thinking, it seems like we should refactor existing files uploading instead of implementing a new method.
We should reuse existing method PostFormAsync

public async Task<HttpResponseMessage> PostFormAsync(
string resource,
IEnumerable<KeyValuePair<string, string>> parameters,
IEnumerable<ByteArrayContent> files,
CancellationToken cancellationToken = default)
{
using (var multipartFormDataContent = new MultipartFormDataContent())
{
foreach (var keyValuePair in parameters)
{
multipartFormDataContent.Add(new StringContent(keyValuePair.Value), $"\"{keyValuePair.Key}\"");
}
foreach (var file in files)
{
multipartFormDataContent.Add(file, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
}
return await _httpClient.PostAsync(resource, multipartFormDataContent, cancellationToken)
.ConfigureAwait(false);
}

But we need to improve it a bit.
We should:

  1. Add mime detection to the existing PostFormAsync
  2. Replace IEnumerable<ByteArrayContent> files with a custom UploadFile model that contains file name and content.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Oct 22, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
13 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@olsh olsh merged commit c4f149e into olsh:master Oct 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants