Downloading files with Chinese characters in the filenames (Base64 bug)

0
0

Dear Team,

I have a problem downloading files for filenames containing certain Chinese characters.

Application.Download(fileStream, sFileName);

Where the filename is for example

(Template_rev12) eFinance IFRS adjustments M01 2023_006_IFRS 24年7月存货调整修正(冲销6月上传7月).xlsx

the filename is Base64 encoded and passes in URL as the x parameter.

/download.wx?res=…&x=…

The problem is that the Base64 encoded filename has a valid “+” character.
Characters ‘+’, ‘/’ and ‘=’ seem to be valid Base64 characters.

ewAiAGYAaQBsAGUAIgA6ACIAIQBcAFwAMwBmADgANAA5ADMAZgBiAC0AYwBlADIAMAAtADQAMgAyADEALQA5AGEAMwBlAC0AOAA3AGMAMwAwADEAOQA0ADEAMQAzADAALgB4AGwAcwB4ACIALAAiAG4AYQBtAGUAIgA6ACIAKABUAGUAbQBwAGwAYQB0AGUAXwByAGUAdgAxADIAKQAgAGUARgBpAG4AYQBuAGMAZQAgAEkARgBSAFMAIABhAGQAagB1AHMAdABtAGUAbgB0AHMAIABNADAAMQAgADIAMAAyADMAXwAwADAANgBfAEkARgBSAFMAIAAyADQAdF43AAhnWFsnjQOMdGXuT2NrCP+yUQCVNgAIZwpOIE83AAhnKQAuAHgAbABzAHgAIgB9AA==

Now when the x parameter is passed back to the HTTPRequest from the browser, the ‘+’ character is replaced by a space, as expected.

ewAiAGYAaQBsAGUAIgA6ACIAIQBcAFwAMwBmADgANAA5ADMAZgBiAC0AYwBlADIAMAAtADQAMgAyADEALQA5AGEAMwBlAC0AOAA3AGMAMwAwADEAOQA0ADEAMQAzADAALgB4AGwAcwB4ACIALAAiAG4AYQBtAGUAIgA6ACIAKABUAGUAbQBwAGwAYQB0AGUAXwByAGUAdgAxADIAKQAgAGUARgBpAG4AYQBuAGMAZQAgAEkARgBSAFMAIABhAGQAagB1AHMAdABtAGUAbgB0AHMAIABNADAAMQAgADIAMAAyADMAXwAwADAANgBfAEkARgBSAFMAIAAyADQAdF43AAhnWFsnjQOMdGXuT2NrCP yUQCVNgAIZwpOIE83AAhnKQAuAHgAbABzAHgAIgB9AA==

So the Base64 decode does not work.
It either scrambles the resulting Chinese characters or throws a decode exception, which Wisej logs into a trace.

Kizaemon

  • You must to post comments
0
0

Thank you!

I could solve the issue with filename encoding by pre-encoding the content disposition filename myself.


string sFileName = "(Template_rev12) eFinance IFRS adjustments M01 2023_006_IFRS 24年7月存货调整修正(冲销6月上传7月).xlsx";

string f = Path.GetFileName(sFileName);
byte[] b = Encoding.GetEncoding(“utf-8”).GetBytes(f);
sFileName = “=?utf-8?B?” + Convert.ToBase64String(b) + “?=”;

string sTempFilePath = “temp.bin”;

FileInfo fi = new FileInfo(sTempFilePath);
using (FileStream fileStream = fi.OpenRead())
Application.Download(fileStream, sFileName);

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.