none
Begin returning a stream to the browser before reading the whole stream from storage?

    Question

  • Hi

    I'm trying to return a stream using a static handler in MVC to a browser (so that I can handle authentication etc). The problem is that the file I am trying to return is a very large one (progressive mp4). On the server side I am using a ResumingFileStreamResult from http://vikingerik.wordpress.com/2011/06/24/asp-net-mvc-resuming-actions/

    It allows me to do byte range requests in MVC for the HTML5 video element.

    Here is the code I am using:

    CloudBlockBlob myBlob = null;
    CloudBlobContainer blobContainer = GetBlobContainer("MyContainer");
    myBlob = blobContainer.GetBlockBlobReference(path);
    ResumingFileStreamResult fsr = new ResumingFileStreamResult(myBlob.OpenRead(), "video/mp4");
    return fsr;

    The problem is that when I call myBlob.OpenRead(), the whole stream is read to the server from storage first... which is both a waste of internal bandwidth and time even though I have placed them in the same affinity group. The video only starts returning to my browser after a minute, instead of instantly when I point the video element directly to the storage blob's URL.

    Any ideas how I can return a stream for a blob as I am filling it from storage so that I can begin returning to the browser instantly?

    Tuesday, November 5, 2013 9:25 AM

Answers

  • After some further investigation, it seems that the issue was not from OpenRead(), but rather how the ResumingFileStreamResult was flushing data to the browser. It was calling response.Output.Flush(). When I changed it to response.Flush, it seems to work. What puzzles me is that this seemed to work last week without modification.

    Oh well. There is something about streams I am missing in my education, but for now this works.

    Tuesday, November 5, 2013 12:04 PM

All replies

  • After some further investigation, it seems that the issue was not from OpenRead(), but rather how the ResumingFileStreamResult was flushing data to the browser. It was calling response.Output.Flush(). When I changed it to response.Flush, it seems to work. What puzzles me is that this seemed to work last week without modification.

    Oh well. There is something about streams I am missing in my education, but for now this works.

    Tuesday, November 5, 2013 12:04 PM
  • Hi,

    Congratulations!

    Thank you for sharing your solutions and experience here. It will be very beneficial for other community members who have similar questions. If you have any difficulty in future programming, we welcome you to post in forums again.

    Best Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, November 6, 2013 1:29 AM
    Moderator