This is happening because ToOptimizedResult
expects to receive a DTO response object that it can compress to create a CompressedResult
response.
However you are providing an HttpResult
which effectively is wrapper for the byte[]
/string
DTO response object of the file you are loading, this wrapper is a complex type, and isn't really what you want to be trying to optimise.
If your file is binary then you should return the byte[]
of the contents, if it is plain text then return a string
. Then the ToOptimizedResult
can optimise that data.
// Binary file type
return File.ReadAllBytes(Path.Combine(path, file)); // returns byte[]
// Plain text file type
return File.ReadAllText(Path.Combine(path, file)); // returns string