Skip to content

Uploaded file has incorrectly encoded filename if this filename has non-ASCII characters #1828

Closed

Description

@inna-artiushenko

Describe the bug
If you try to upload a file that has non-ASCII characters in its filename (eg. ÄÖäö.jpg), then Content-Disposition is encoded to smth like "=?utf-8?B?S29hbGHDhMOWw6TDti5qcGc=?="

To Reproduce

  1. Set a breakpoint to https://github.com/restsharp/RestSharp/blob/dev/src/RestSharp/Request/RequestContent.cs#L65
  2. Rename test file Koala.jpg to KoalaÄÖäö.jpg
  3. Change test data (to filename = "KoalaÄÖäö.jpg") and run an upload test eg. Should_upload_from_file
  4. Check fileContent.Headers.ContentDisposition value in RequestContent.AddFiles()

Expected behavior
fileContent.Headers.ContentDisposition - form-data; name="file"; filename="ÄÖäö.jpg"

Actual behavior
fileContent.Headers.ContentDisposition - form-data; name="file"; filename="=?utf-8?B?S29hbGHDhMOWw6TDti5qcGc=?="

Notes
For a file like Koala.jpg fileContent.Headers.ContentDisposition is form-data; name="file"; filename="Koala.jpg".
Initially, it's an issue with ContentDispositionHeaderValue (microsoft/referencesource#140), but I don't know how to fix it there.

Activity

  1. asynchk commented on Apr 8, 2022

    @asynchk

    Thanks for raising the issue I am facing the same problem

  2. stale commented on Jun 23, 2022

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  3. repo-ranger commented on Jun 23, 2022

    @repo-ranger

    ⚠️ This issue has been marked wontfix and will be closed in 3 days

  4. PooraniPerumal commented on Jul 5, 2022

    @PooraniPerumal

    I am facing the same issue.

  5. alexeyzimarev commented on Jul 7, 2022

    @alexeyzimarev
    Member

    I'd like to know more about the issue itself. Why is the current behaviour wrong? We have an integrated test that sends the file to an echo upload API, and it works with both ASCII and non-ASCII characters. Do you have a specific server that for some reason is unable to understand web standards?

  6. PooraniPerumal commented on Jul 7, 2022

    @PooraniPerumal
  7. alexeyzimarev commented on Jul 7, 2022

    @alexeyzimarev
    Member

    Normally, the server should be able to decide the MIME-encoded filename. The current implementation, however, doesn't support the filename* parameter, which is the UTF-8 encoded filename. It worked before. I think the reason for using the current code is that the default values aren't enclosed in quotes and it broke some other servers.

    I wish that people who develop servers spend some time reading the docs about how this all should work... Checking some other things now.

  8. alexeyzimarev commented on Jul 7, 2022

    @alexeyzimarev
    Member

    Ok, I am sorry to say but your code doesn't work. I will create another PR. When I made it work as you expected it to work (without encoding), the tests fail as the ASP.NET Core WebAPI doesn't like it. These tests only passed because your code didn't work. What you got, in fact, is the filename* parameter in the header, which is currently disabled by default.

  9. added a commit that references this issue on Jul 7, 2022
    47164b7
  10. alexeyzimarev commented on Jul 7, 2022

    @alexeyzimarev
    Member

    You can try the latest preview and add the file parameter like this:

    request.AddFile(...., options: new FileParameterOptions { DisableFilenameEncoding = true });
    

    I think it won't work, but it actually does what you wanted.

    You can also try:

    request.AddFile(...., options: new FileParameterOptions { DisableFileNameStar = false });
    

    and I expect it to solve the actual issue.

  11. added a commit that references this issue on Jan 27, 2024
    c969747
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions