0

I try to use flurl to send a file like this:

public ImportResponse Import(ImportRequest request, string fileName, Stream stream)
    {
        request).PostAsync(content).Result<ImportTariffResponse>();

        return FlurlClient(Routes.Import, request).PostMultipartAsync(mp => mp.AddJson("json", request).AddFile("file", stream, ConvertToAcsii(fileName))).Result<ImportResponse>();
    }

fileName = "Файл импорта тарифов (1).xlsx"

But in post method I get this:

Request.Files.FirstOrDefault().FileName = "=?utf-8?B?0KTQsNC50Lsg0LjQvNC/0L7RgNGC0LAg0YLQsNGA0LjRhNC+0LIgKDEpLnhsc3g=?="

Any suggestions?

Todd Menier
  • 37,557
  • 17
  • 150
  • 173
EKostan
  • 11
  • 4

1 Answers1

2

The filename appears to be encoded using MIME encoded-word syntax. (Flurl doesn't do this directly, it presumably happens deeper down in the HttpClient libraries when non-ASCII characters are detected.) .NET doesn't directly support decoding this format, but you can do it yourself fairly easily. If you strip the =?utf-8?B? from the beginning and ?= from the end, what you're left with is your filename base64 encoded.

Here's one way you could do it:

var base64 = Request.Files.FirstOrDefault().FileName.Split('?')[3];
var bytes = Convert.FromBase64String(base64);
var filename = Encoding.UTF8.GetString(bytes);
Todd Menier
  • 37,557
  • 17
  • 150
  • 173