I use Asp.Net API (.Net 5) in my backend. I use blazor wasm in my frontend.
A method of my controller is:
public FileContentResult GetExport()
{
var IndividualBl = new IndividualBl();
return ResultBlob(IndividualBl.GetExport(), "individual-export.xlsx");
}
protected FileContentResult ResultBlob(byte[] byteArray, string fileName)
{
return File(byteArray, "application/octet-stream", fileName);
}
When I use Swagger, I download the file with the name included in the header. My Response Headers:
access-control-allow-origin: *
content-disposition: attachment; filename=individual-export.xlsx; filename*=UTF-8''individual-export.xlsx
content-length: 4218
content-type: application/octet-stream
date: Mon, 23 Nov 2020 14:39:34 GMT
server: Microsoft-IIS/10.0
status: 200
x-powered-by: ASP.NET
Now I try to get this file by service :
public async Task<StreamFileModel> GetExport()
{
var url = $"{_httpClient.BaseAddress}{IndividualUrls.IndividualController}/{IndividualUrls.GetExport}";
var result = await _httpClient.GetAsync(url);
var header = result.Content.Headers.ContentDisposition;
var content = await result.Content.ReadAsByteArrayAsync();
return new StreamFileModel
{
File = content,
Name = header.FileName
};
}
My content is OK but the header is null (= ContentDisposition is null)
It is not the good method to get the content-disposition value?
Thanks