Skip to content

Commit

Permalink
filehandler: add range in stream
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhorukovAnton committed Jan 26, 2024
1 parent adb6fef commit db5845a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions products/ASC.Files/Core/HttpHandlers/FileHandler.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,15 +780,13 @@ private async Task StreamFileAsync<T>(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)
{
Expand Down

0 comments on commit db5845a

Please sign in to comment.