Browse Source

Fixed length for limiting amount to write to response

tags/2.0.6
Teknikode 3 years ago
parent
commit
72d9c7a115
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      Teknik/Areas/Upload/Controllers/UploadController.cs

+ 5
- 4
Teknik/Areas/Upload/Controllers/UploadController.cs View File

@@ -178,7 +178,7 @@ namespace Teknik.Areas.Upload.Controllers
// Read in the file
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
// We accept ranges
Response.AddHeader("Accept-Ranges", "0-" + upload.ContentLength);
Response.AddHeader("Accept-Ranges", "0-" + length);

// check to see if we need to pass a specified range
if (byRange)
@@ -296,13 +296,14 @@ namespace Teknik.Areas.Upload.Controllers
int curByte = 0;
int processedBytes = 0;
byte[] buffer = new byte[chunkSize];
int bytesToRead = chunkSize;
do
{
if (curByte + chunkSize > length)
{
chunkSize = length - curByte;
bytesToRead = chunkSize - ((curByte + bytesToRead) - length);
}
processedBytes = AES.ProcessCipherBlock(cipher, fileStream, chunkSize, buffer, 0);
processedBytes = AES.ProcessCipherBlock(cipher, fileStream, bytesToRead, buffer, 0);
if (processedBytes > 0)
{
response.OutputStream.Write(buffer, 0, processedBytes);
@@ -313,7 +314,7 @@ namespace Teknik.Areas.Upload.Controllers
}
curByte += processedBytes;
}
while (processedBytes > 0 && curByte < length);
while (processedBytes > 0 && curByte <= length);

// Clear the buffer
Array.Clear(buffer, 0, chunkSize);

Loading…
Cancel
Save