I have a function in my SPA that sends a request to our service endpoint in Microsoft Azure, requesting a file (PDF in this case). Downloading this file causes the name on the file to be, correct me if I'm wrong, as encoded for Safari on MacOS.
I have come to an understanding that Safari or MacOS uses UTF8, a string written in .net framework on a windowsmachine would be UTF16, but for test purposes I'm writing the filename directly into the ContentDispositionHeaderValue
, code sample below:
var result = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(data)
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Brännoljegatan 4.pdf",
CreationDate = DateTimeOffset.UtcNow
};
Using my SPA now, requesting this file would output as follow:
Chrome: "Brännoljegatan 4.pdf"
Safari: =?utf-8?B?QnLDpG5ub2xqZWdhdGFuIDQucGRm?=
string fileName = Uri.EscapeDataString("Brännoljegatan 4.pdf");
result.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = fileName,
CreationDate = DateTimeOffset.UtcNow
};
Code above would result in:
Chrome: "Brännoljegatan 4.pdf"
Safari: Br%C3%A4nnoljegatan%204.pdf"
This is where I really don't know how to continue getting the filename to be correct for Safari. Our browser targets are:
- Chromium based (Chrome, MS Edge)
- Internet Explorer 11
- Safari
Sadly Safari is the only black sheep so far.
I want the downloaded file to be named "Brännoljegatan 4.pdf" for Safari, of course the remaining swedish characters (å Å, ä Ä, ö Ö)
Do you have any suggestions?