Open Closed

File Management download exception #3678


User avatar
0
AlderCove created
  • ABP Framework version: v5.1.4
  • UI type: Angular / MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:

2022-09-09 15:02:55.907 +00:00 [ERR] Invalid non-ASCII or control character in header: 0x00E9 System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x00E9

  • Steps to reproduce the issue:"
  1. upload a file with non-ascii character in name
  2. download the file

Hi

We are also experiencing this issue: https://support.abp.io/QA/Questions/3563/File-Management-file-download-exception

Our solution was to encode the file name before adding the header:

        var fileName = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(fileDescriptor.Name));

However, this will result in a difference in the name of the original uploaded file and the downloaded file name.

Do you have a workaround solution that you can share that addresses this, as per #3563?

Thanks


1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    You can override the DownloadAsync method in FileDescriptorController and update it as follows:

    var fileDescriptor = await FileDescriptorAppService.GetAsync(id);
    
    Response.Headers.Add("Content-Disposition", $"attachment;filename=\"{HttpUtility.UrlEncode(fileDescriptor.Name)}\""); // this has changed
    Response.Headers.Add("Accept-Ranges", "bytes");
    Response.ContentType = fileDescriptor.MimeType;
    
            return await FileDescriptorAppService.DownloadAsync(id, token);
    

    We solved the problem with HttpUtility.UrlEncode. But if you know of a better solution, please let us know.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15