Closed mansai closed 4 years ago
@mansai I think it should be the following
[HttpGet]
[AutoWrapIgnore]
public async Task<FileStreamResult> GetExcel()
{
var filePath = "test.txt";
var file = System.IO.File.OpenRead(filePath);
var provider = new FileExtensionContentTypeProvider();
var fileInfo = new System.IO.FileInfo(filePath);
var memi = provider.Mappings[fileInfo.Extension];
return File(file, memi, fileInfo.Name);
}
@mansai Ok, I have reproduced the problem, you can first use the following code snippet to return your expected result.
app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions
{
IsApiOnly = false,
});
There are still problems
@mansai I'm sorry I can't reproduce your results. I do n’t know if you have executed dotnet build
, or to better solve the problem, I suggest you provide a reproducible demo
@mansai Thanks for the feedback! I appreciate it. This should now be resolved with the latest release here: https://www.nuget.org/packages/AutoWrapper.Core/4.2.0
Sample usage:
[HttpGet("getfile")]
[AutoWrapIgnore]
public FileStreamResult GetFile2()
{
var filePath = $"{Environment.CurrentDirectory}/Logs/log_20200501.txt";
var file = System.IO.File.OpenRead(filePath);
var provider = new FileExtensionContentTypeProvider();
var fileInfo = new System.IO.FileInfo(filePath);
var memi = provider.Mappings[fileInfo.Extension];
return File(file, memi, fileInfo.Name);
}
[HttpGet("getfile2")]
[AutoWrapIgnore]
public FileStreamResult GetFile()
{
var path = $"{Environment.CurrentDirectory}/Logs/log_20200501.txt";
var stream = System.IO.File.OpenRead(path);
return new FileStreamResult(stream, "application/octet-stream");
}
[HttpGet("getpdf")]
[AutoWrapIgnore]
public IActionResult GetPdf()
{
var path = $"{Environment.CurrentDirectory}/sample.pdf";
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
return new FileContentResult(fileBytes, "application/pdf");
}
[HttpGet("getpdf2")]
[AutoWrapIgnore]
public IActionResult GetPdf2()
{
var path = $"{Environment.CurrentDirectory}/sample.pdf";
var stream = new FileStream(path, FileMode.Open);
return new FileStreamResult(stream, "application/pdf");
}
//returns text/plain
[HttpGet("getstring")]
[AutoWrapIgnore]
public ContentResult GetString()
{
return Content("Hello");
}
txt file download ok,Unable to open Excel or pdf,content-length changed
@mansai
I've released v4.2.2 here: https://www.nuget.org/packages/AutoWrapper.Core/4.2.2
Please update to that and it should fix the issue.
Thanks!
[HttpPost]
[AutoWrapIgnore] public async Task< FileStreamResult> GetExcel() { var filePath = "xxx..xlsx"; var file = System.IO.File.OpenRead(filePath); var provider = new FileExtensionContentTypeProvider();
var fileInfo = new System.IO.FileInfo(filePath);
var memi = provider.Mappings[fileInfo.Extension]; return File(file, memi, fileInfo.Name); } Bug: content-type: application/json
Right: content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet