Jump to content
BertB

HttpStratFile fails for large files

Recommended Posts

Sometimes I need to download large files, so instead of saving ResponseStream to file, I change my code to use:

SslHttpRestData.HttpMemStrategy := HttpStratFile;
SslHttpRestData.HttpDownFileName := DiskFileName;
SslHttpRestData.HttpDownReplace := True;

 

The download is running and takes quite some time for large files, but the saved file is very often only 24576 bytes in size.

 

09:48:24 < HTTP/1.1 200 OK
09:48:24 < Content-Length: 144538644
09:48:24 < Content-Type: audio/mpeg
09:48:24 < Server: Microsoft-IIS/10.0
09:48:24 < Strict-Transport-Security: max-age=2592000
09:48:24 < X-Powered-By: ASP.NET
09:48:24 < Date: Tue, 30 Apr 2024 07:48:23 GMT
09:48:24 Opened new file OK: E:\store\2504.mp3.part
09:48:24 https:***2504.mp3, Downloading 0 of 138M
09:48:26 https:***2504.mp3, Downloading 27,0M of 138M
09:48:28 https:***2504.mp3, Downloading 61,3M of 138M
09:48:30 https:***2504.mp3, Downloading 97,5M of 138M
09:48:32 https:***2504.mp3, Downloading 125M of 138M
09:48:32 Request completed: 200 OK
09:48:32 Saved File OK: E:\store\2504.mp3, Size: 138M
09:48:32 https:***202504.mp3, Request completed, Size: 138M

 

A correct file size is reported but that is not true.

Disk space is no problem, using version 9.1 with Delphi 12.

 

Am I doing something wrong, or what?

 

Bert

 

Share this post


Link to post

I just tested the 'HTTP Rest Download' function in the snippets sample, that downloads a 300M file from my server, same code as yours, I get a 300M file.  How are you reporting the size downloaded?

 

Beware the V9.1 snippets sample won't download from my server any longer, I added server authentication to test something else, and you'll need a new snippets from SVN or the overnight zip that adds authentication as well.

 

Angus

 

Share this post


Link to post
  SslHttpRestData.DebugLevel := DebugHdr;
  SslHttpRestData.OnHttpRestProg := onSslHttpRestProg;

Procedure onSslHttpRestProg logs Msg to a file.

 

Share this post


Link to post

Generally, in the progress event, you check the LogLevel so that LoglevelProg is displayed, not logged every two seconds during the download, as you did in your example above, although does not really matter for small files. 

 

The component reports the HTTP reported size at the end and does not check the actual file, the snippet sample checks the real size after download.

 

Angus

 

Share this post


Link to post

I think that I found the problem: Reset property HttpMemStrategy to HttpStratMem after download.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×