Azure Function Range Header for reading Blob Storage Video stream using too much data

Viewed 216

I'm using the following code to read a Range Header from an HttpRequestMessage object to determine how to read a video file and send the data back (so it streams):

private static bool GetHttpRange(RangeItemHeaderValue rangeItemHeaderValue, long contentLength, out HttpRange httpRange)
{
    httpRange = new HttpRange();

    long actualContentLength = contentLength - 1;

    if (rangeItemHeaderValue.From != null)
    {
        httpRange.From = rangeItemHeaderValue.From.Value;

        if (rangeItemHeaderValue.To != null)
        {
            httpRange.To = rangeItemHeaderValue.To.Value;
        }
        else
        {
            httpRange.To = actualContentLength;
        }
    }
    else
    {
        httpRange.To = actualContentLength;

        if (rangeItemHeaderValue.To != null)
        {
            httpRange.From = contentLength - rangeItemHeaderValue.To.Value;
        }
        else
        {
            httpRange.From = 0;
        }
    }

    return httpRange.From < contentLength && httpRange.To < contentLength;
}

This streams the video perfectly! However, the requests for iPhones and Apple TVs are random and a 200MB video ends up reading 5GB of data from Blob Storage.

Is there any way to stop this from happening?

0 Answers
Related