Click here to Skip to main content
15,884,978 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have the following Controller for getting file:

C#
[SessionState(SessionStateBehavior.Disabled)]
public class FileController : BaseController
{
    [HttpGet]
    public FileResult Index(long id)
    {
        if (id <= 0) return null;
        Attachment attachment = Service.GetAttachmentById(id);
        if (attachment == null) return null;
        new Task(() => Service.IncreaseAttachmentViewCount(id)).Start();
        string filename = attachment.Name;
        //"application/octet-stream";
        string mimeType = System.Web.MimeMapping.GetMimeMapping(filename);
        return File(attachment.Path, mimeType);
    }
}

It's OK and works well but it doesn't work with ImagResizer[^] API
e.g:
The following image shows in natural size(1920*1200) and maxwidth or maxheight doesn't work at all. But if I use the absolute file path it works.

HTML
<img src="File/Index/1231?maxwidth=300&maxheight=300" alt="" />
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900