@@ -277,29 +277,49 @@ public async Task<IActionResult> GetFileStream(string idChannel, string idFile,
277277 var rangeHeader = request . Headers [ "Range" ] . ToString ( ) ;
278278
279279 var file = await _fs . getItemById ( idChannel , idFile ) ;
280+ long totalLength = file . Size ;
280281
281282 TL . Message idM = await _ts . getMessageFile ( idChannel , file . MessageId ?? file . ListMessageId . FirstOrDefault ( ) ) ;
282283
283- long totalLength = 0 ; // (await _fs.getItemById(idChannel, idFile)).Size ;
284+ long totalPartialFileLength = 0 ;
284285
285- if ( idM . media is MessageMediaDocument { document : Document document } )
286+ if ( idM . media is MessageMediaDocument { document : Document document } )
286287 {
287- totalLength = document . size ;
288+ totalPartialFileLength = document . size ;
288289 }
289290
290291 long from = 0 ;
291292 long initialFrom = 0 ;
293+ long initialPartFrom = 0 ;
292294 long to = 0 ;
293295
294296 if ( ! string . IsNullOrEmpty ( rangeHeader ) && rangeHeader . StartsWith ( "bytes=" ) )
295297 {
296298 var range = rangeHeader . Replace ( "bytes=" , "" ) . Split ( '-' ) ;
297299 from = long . Parse ( range [ 0 ] ) ;
298300 initialFrom = from ;
301+ initialPartFrom = from ;
299302 if ( range . Length > 1 && ! string . IsNullOrEmpty ( range [ 1 ] ) )
300303 to = long . Parse ( range [ 1 ] ) ;
301304 }
302305
306+ if ( from >= totalPartialFileLength )
307+ {
308+ Console . WriteLine ( "Take a file part: from: " + from + ", totalPartialFileLength: " + totalPartialFileLength ) ;
309+ int filePart = 0 ;
310+ while ( from >= totalPartialFileLength )
311+ {
312+ filePart ++ ;
313+ from -= totalPartialFileLength ;
314+ }
315+ idM = await _ts . getMessageFile ( idChannel , file . ListMessageId [ filePart ] ) ;
316+ if ( idM . media is MessageMediaDocument { document : Document document2 } )
317+ {
318+ totalPartialFileLength = document2 . size ;
319+ }
320+ initialPartFrom = from ;
321+ }
322+
303323 if ( from > 0 )
304324 {
305325 from = ( from / 524288 ) * 524288 ;
@@ -315,12 +335,12 @@ public async Task<IActionResult> GetFileStream(string idChannel, string idFile,
315335 else
316336 to = ( ( to + 524288 ) / 524288 ) * 524288 ;
317337
318- if ( to > totalLength )
338+ if ( to > totalPartialFileLength )
319339 {
320- to = totalLength ;
340+ to = totalPartialFileLength ;
321341 }
322342
323- if ( totalLength == initialFrom )
343+ if ( totalPartialFileLength == initialPartFrom )
324344 {
325345 Response . StatusCode = 416 ; // Range Not Satisfiable
326346 Response . Headers [ "Content-Range" ] = $ "bytes */{ totalLength } ";
@@ -335,7 +355,7 @@ public async Task<IActionResult> GetFileStream(string idChannel, string idFile,
335355
336356 //Console.WriteLine("Total download length: " + data.Length);
337357
338- long skipedBytes = initialFrom - from - ( length - data . Length ) ;
358+ long skipedBytes = initialPartFrom - from - ( length - data . Length ) ;
339359
340360 if ( skipedBytes < 0 ) skipedBytes = 0 ;
341361
0 commit comments