Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Response.AsAttachment issue: cannot get response if set filename to Chinese text #2992

Open
4 tasks
Summer006 opened this issue Nov 3, 2019 · 1 comment
Open
4 tasks

Comments

@Summer006
Copy link

Prerequisites

  • [*] I have written a descriptive issue title
  • [*] I have verified that I am running the latest version of Nancy
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • [*] I have searched open and closed issues to ensure it has not already been reported

Description

I want to return a file by url like: http://.../getfile?filename=xxxxx
my code is like this:

var file = new FileStream(zipPath, FileMode.Open);
string fileName = //set a filename
var response = new StreamResponse(() => file, MimeTypes.GetMimeType(fileName));
return response.AsAttachment(fileName);

when filename is us letter, all ok.
when filename include chinese, client cannot get any response, but also no exception.

when I change AsAttachment section to :
AsAttachment("fixednamehere.xxx");
it goes well

so I guess is AsAttachment issue.

ps: if only include one or two chinese word, it still ok, client can download file, but got wrong filename. if it include many chinese word, it stuck

System Configuration

  • Nancy version:
  • Nancy host
    • Nancy.Hosting.Aspnet
    • [*] Nancy.Hosting.Self
    • Nancy.Owin ()
    • Other:
  • Other Nancy packages and versions:
  • Environment (Operating system, version and so on):
  • .NET Framework version:
  • Additional information:
@0x414c49
Copy link

Have you tried to encode the file name?

Something like:

// using Nancy.Helpers;

return response.AsAttachment(HttpUtility.UrlEncode(fileName));

HttpUtility is a Nancy helper class.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants