From db5845a8d76f704032a66bed2daba6c2c3cf702e Mon Sep 17 00:00:00 2001 From: Sukhorukov Anton Date: Fri, 26 Jan 2024 12:28:23 +0300 Subject: [PATCH] filehandler: add range in stream --- .../ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs b/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs index e50d1f428aa..20e88c39f43 100644 --- a/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs +++ b/products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs @@ -780,15 +780,13 @@ private async Task StreamFileAsync(HttpContext context, T id) return; } - context.Response.Headers.Add("Content-Disposition", ContentDispositionUtil.GetHeaderValue(file.Title)); - context.Response.ContentType = MimeMapping.GetMimeMapping(file.Title); + long offset = 0; + var length = ProcessRangeHeader(context, file.ContentLength, ref offset); await using var stream = await fileDao.GetFileStreamAsync(file); - context.Response.Headers.Add("Content-Length", - stream.CanSeek - ? stream.Length.ToString(CultureInfo.InvariantCulture) - : file.ContentLength.ToString(CultureInfo.InvariantCulture)); - await stream.CopyToAsync(context.Response.Body); + stream.Seek(offset, SeekOrigin.Begin); + + await SendStreamByChunksAsync(context, length, file.Title, stream, true); } catch (Exception ex) {