[Mono-dev] Bug in mono 3.0.1 MVC3 File/FileResult

Daniel Lo Nigro lists at dan.cx
Thu Jan 31 21:56:40 UTC 2013


Not a bug in Mono, you're just sending the wrong mime-type (and the browser
isn't recognising that it's an image). image/jpg should actually be
image/jpeg.

I noticed you're using Nginx, I'd probably use a custom ActionResult that
uses the X-Accel-Redirect header <http://wiki.nginx.org/XSendfile> for
better performance. This lets Nginx serve the file based on a HTTP header
your code returns.


On Wed, Jan 30, 2013 at 2:59 AM, SirNoSkill <quandary82 at hailmail.net> wrote:

>
> There is a bug in mono 3.0.1.
> I don't know if it is fixed in 3.0.3
>
>
> If in a asp.net MVC3 controller, I call File via path (probably uses
> FilePathResult)
> like this
>
> http://www.daniel-steiger.ch/gallery/FullImage/001.jpg?no_cache=1358694795000
>
> I get the image data as text.
> The path is correct.
> The mime is correct.
> The image itselfs is valid.
>
> If I call the url to the image directly and not via the "File" method,
> then it works
> Proof:
>
> http://www.daniel-steiger.ch/Content/images/gallery/002.jpg?LastWriteTimeUTC=1358694795000
>
> Ironically, generating the thumbnail works (that probably goes via
> FileStreamResult).
> Both work correctly on windows.
>
>
> PS:
> The latest-stable install script for xsp misses copying
> fastcgi-mono-server4, mod-mono and xsp  to the 4.5 gac.
> Same things applies to Microsoft.VisualBasic.dll.
> See here:
>
> http://stackoverflow.com/questions/4239645/does-the-razor-view-engine-work-for-mono
>
>
>
>
> namespace Homepage.Controllers
> {
>
>
>     public class GalleryController : Controller
>     {
>
>
>         protected static string GetImageDirectory()
>         {
>             string bd = AppDomain.CurrentDomain.BaseDirectory;
>             string strImageDirectory = System.IO.Path.Combine(bd,
>             "Content");
>             strImageDirectory =
>             System.IO.Path.Combine(strImageDirectory, "images");
>             strImageDirectory =
>             System.IO.Path.Combine(strImageDirectory, "gallery");
>
>             return strImageDirectory;
>         } // End Function GetImageDirectory
>
>
>         protected static string strImageDirectory = GetImageDirectory();
>
>
>         public FileResult FullImage(string id)
>         {
>             string strFileName =
>             System.IO.Path.Combine(strImageDirectory, id);
>
>             //return new FilePathResult("CorrectFullPathAndFileName",
>             "CorrectMime");
>             return File(strFileName, "image/jpg");
>         } // End Action FullImage
>
>
>
>         public FileResult Thumb(string id)
>         {
>             //return Redirect(id);
>
>             string strFileName =
>             System.IO.Path.Combine(strImageDirectory, id);
>
>             System.IO.Stream ms =
>             Tools.Imaging.GetThumbnailStream(strFileName,
>             System.Drawing.Imaging.ImageFormat.Png);
>             return File(ms, "image/png");
>             /*
>             using (System.IO.Stream ms =
>             Tools.Imaging.GetThumbnailStream(strFileName,
>             System.Drawing.Imaging.ImageFormat.Png))
>             {
>                 return File(ms, "image/png");
>             }*/
>         } // End Action Thumb
>
>
>     } // End Class GalleryController : Controller
>
>
> } // End Namespace Homepage.Controllers
>
>
>
> --
>   SirNoSkill
>   quandary82 at hailmail.net
>
> --
> http://www.fastmail.fm - Email service worth paying for. Try it for free
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20130201/a9dd734e/attachment.html>


More information about the Mono-devel-list mailing list