NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.46k forks source link

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

Open Summer006 opened 5 years ago

Summer006 commented 5 years ago

Prerequisites

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

0x414c49 commented 4 years ago

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.