'How do I fix a "System.Net.Http.HttpRequestException: TypeError: Failed to fetch" in Blazor WebAssembly?

The code below, runs for about fifteen seconds on the "dataFs = await _Http.GetStreamAsync(BODIST_DATA_HTTPNAME)" line before failing with a "System.Net.Http.HttpRequestException: TypeError: Failed to fetch".

        public async Task<Double> EffectivePipCount(HttpClient _Http, Int64 _PositionId)
        {
            Double retVal = Double.NaN;
            using (Stream locnFs = await _Http.GetStreamAsync(BODIST_LOCATION_FILENAME)
                            , dataFs = await _Http.GetStreamAsync(BODIST_DATA_FILENAME))
            {
                retVal = EffectivePipCount(_PositionId, locnFs, dataFs);
            }
            return retVal;
        }

The file in question is about four gigabytes in size.

This is in Blazor WebAssembly app, so I want an Http equivalent to a FileStream, where I can seek and then read the hundreds of bytes I want. Small files in the same directory work fine.

If the problem is a timeout because of the file size, what should I be using instead of HttpClient.GetStreamAsync()?



Solution 1:[1]

My best guess is that GetStreamAsync() pulls down the whole file. Using http.GetFromJsonAsync solves the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hal Heinrich