1

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.

yass1n3
  • 7
  • 3
  • Possible duplicate of [How to encode the filename parameter of Content-Disposition header in HTTP?](https://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http) – Markus Dec 05 '17 at 16:15
  • The character set of `filename`is very limited; you can use `filename*`. Especially this answer to the above question should give you a lot of details: https://stackoverflow.com/a/6745788/642579 – Markus Dec 05 '17 at 16:15

0 Answers0