Problem dotyczy FileContentResult i FileStreamResult. W teorii wiem do czego który służy, a jednak tylko FileContentResult udaje mi się użyć poprawnie.
Akacja GetImage jest pewnego kotrolera zwraca obrazek jpeg. Zakładam, że currentImage istnieje i nie jest równy null.
Działająca wersja:
public ActionResult GetImage()
{
FileContentResult result;
using (var ms = new MemoryStream())
{
currentImage.Save(ms, ImageFormat.Jpeg);
result = File(ms.GetBuffer(), "image/jpeg");
}
return result;
}
Niedziałająca wersja:
public ActionResult GetImage()
{
FileStreamResult result;
using(var ms = new MemoryStream())
{
currentImage.Save(ms, ImageFormat.Jpeg);
result = new FileStreamResult(ms, "image/jpg");
};
return result;
Chciałbym dowiedzieć się dlaczego drugi kod nie działa(?).