filestreamresult

FileStreamResult displays empty browser document when rendering image from stream in MVC3

北慕城南 提交于 2019-12-22 00:32:10
问题 I have a fairly simple Action in an MVC3 application that should render an image... public FileStreamResult Photo(int id) { //get the raw bytes for the photo var qry = from p in db.Photos where p.PhotoID == id select p.PhotoData; var data = qry.FirstOrDefault(); var mem = new MemoryStream(data); var fs = new FileStreamResult(mem, "image/jpeg"); return fs; } When i run this i get a blank document in Chrome, Firefox displays the URL in the actual document area and IE renders the raw bytes.

c# Asp.NET MVC downloading excel file using FileStreamResult

风流意气都作罢 提交于 2019-12-14 03:59:02
问题 I need to build a method, that will receive model, build excel from it (building and receiving part is done without problems) and then export (let user download it) using memory stream (without saving it on the server). I am new to ASP.NET and MVC so i found guide and built this as a tutorial project: public FileResult Download() { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft

MVC3 + Streaming images from the Database is causing very high CPU usage on my server

走远了吗. 提交于 2019-12-11 19:48:53
问题 I have this site that streams images from the database (SQL2008), and I think it's the one causing the very high CPU usage on my server. The CPU usage is at least 60-90%. I am using MVC3 and below is the code in my Controller that sends the image to the View: [OutputCache(Duration = 86400, VaryByParam = "GUID")] public FileStreamResult GetFile(string guid) { Guid id = new Guid(guid); Thumbnail thumbnail = thumbService.GetThumbnailByGUID(id); Stream stream = new MemoryStream(thumbnail

FileStreamResult displays empty browser document when rendering image from stream in MVC3

↘锁芯ラ 提交于 2019-12-04 21:08:26
I have a fairly simple Action in an MVC3 application that should render an image... public FileStreamResult Photo(int id) { //get the raw bytes for the photo var qry = from p in db.Photos where p.PhotoID == id select p.PhotoData; var data = qry.FirstOrDefault(); var mem = new MemoryStream(data); var fs = new FileStreamResult(mem, "image/jpeg"); return fs; } When i run this i get a blank document in Chrome, Firefox displays the URL in the actual document area and IE renders the raw bytes. Chrome gives me a message: Resource interpreted as Document but transferred with MIME type image/jpeg This

Stream MP3 file MVC3

早过忘川 提交于 2019-12-03 07:57:47
I am trying to stream a file using the audio HTML5 tag. I have put the Controller action to return a FileStream and attached it to the src for the audio. However, the content is not loading into the audio tag and doesn't play when I press the default play button. I know the controller is working when I access the src directly. However, it doesn't work in the HTML5 audio tag. Can anyone tell me what I am missing? You should not return a FileStream , you should return a FileStreamResult or a FilePathResult from your controller action, like this: public class HomeController : Controller { public

With FileStreamResult, how is the MemoryStream closed?

懵懂的女人 提交于 2019-12-01 02:04:49
The following code works, but I'm wondering if the MemoryStream created is closed properly. How should this be performed or does FileStreamResult handle it for me? public FileStreamResult DownloadBudgetedRoleOpportunities( Guid projectGuid, IEnumerable<Guid> guidRequiredRoles) { var rolebroker = new ProjectRoleBudgetBroker(); var memstream = rolebroker.CreateBudgetedRoleOpportunies( projectGuid, guidRequiredRoles); var fsr = new FileStreamResult ( memstream, "application/csv" ) { FileDownloadName = "RoleOpportunities.csv" }; // memstream.Close(); throws exception return fsr; } The

With FileStreamResult, how is the MemoryStream closed?

故事扮演 提交于 2019-11-30 22:20:03
问题 The following code works, but I'm wondering if the MemoryStream created is closed properly. How should this be performed or does FileStreamResult handle it for me? public FileStreamResult DownloadBudgetedRoleOpportunities( Guid projectGuid, IEnumerable<Guid> guidRequiredRoles) { var rolebroker = new ProjectRoleBudgetBroker(); var memstream = rolebroker.CreateBudgetedRoleOpportunies( projectGuid, guidRequiredRoles); var fsr = new FileStreamResult ( memstream, "application/csv" ) {

ASP.NET MVC FileStreamResult not working as intended

笑着哭i 提交于 2019-11-29 01:05:50
I have the following code which I stripped out of any non-essential lines to leave the minimun reproducable case. What I expect is for it to return the image, but it doesn't. As far as I can see it returns an empty file: public ActionResult Thumbnail(int id) { var question = GetQuestion(db, id); var image = new Bitmap(question.ImageFullPath); MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Jpeg); return new FileStreamResult(stream, "image/jpeg"); } Can you identify what's wrong with this code? In the debugger I can see that the stream grows in size so it seems to be