Working o an webapi application with angularJS as UI. When I download a file to my desktop from my application. The name is changed replacing some characters like 'é','ü' with characters like these é. The code used to donwload the file is the following.
[HttpGet, Route("{documentid}/raw", Order = 5)]
public IHttpActionResult GetDocumentRaw(string documentid)
{
var service = ResolveService<IDocumentService>();
var raw = service.GetRaw(documentid);
if (raw.Data == null)
{
return NotFound();
}
var fileName = raw.FileName?.GetCleanFileName();
var contentType = raw.ContentType;
if (String.IsNullOrWhiteSpace(fileName))
{
fileName = "rawdata";
}
if (String.IsNullOrWhiteSpace(contentType))
{
contentType = "application/octet-stream";
}
var response = Request.CreateResponse(HttpStatusCode.OK);
Stream stream = new MemoryStream(raw.Data);
response.Content = new StreamContent(stream);
response.Content.Headers.Remove("content-type");
response.Content.Headers.Add("content-type", contentType);
response.Content.Headers.Add("content-disposition", "inline; filename=\"" + fileName + "\"");
response.Content.Headers.Add("content-length", stream.Length.ToString());
response.Content.Headers.Remove("x-filename");
response.Content.Headers.Add("x-filename", fileName);
return ResponseMessage(response);
}
In the UI side, this function is used to download the file.
$download: function(propertyTypeKey) {
$http
.get(this.url + '/raw', {
responseType: 'arraybuffer',
params: {
propertyTypeKey: propertyTypeKey
}
})
.then(function (response) {
DownloadService.downloadFile(
response.data,
response.headers('content-type'),
response.headers('x-filename')
);
});
},
Is this something related to textformat encoding ? Should I add some configuration in the Http Response ? Or may be it is related to the configuration of the IIS Server ? I firstly suspected my chrome navigator but I'm facing the same issue on IE.
Thank you.