Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

How to save multiple resource files locally in CEF4

Post Reply
KsWang
Posts: 3
Joined: Wed Jun 21, 2023 3:34 pm

How to save multiple resource files locally in CEF4

Post by KsWang »

How to save multiple resources when implementing a single resource save in the 'ResponseFilterBrowser' demo?

I customize:
TFilterRecord=record
CompleteState:integer;
url:string;
Stream:TMemorystream;
TDictionary<TCustomResponseFilter ,TFilterRecord>;
TDictionary<string ,TCustomResponseFilter>;

In the 'GetResourceResponseFilter' event, use TDictionary<string ,TCustomResponseFilter> store each 'Request.URL' that requires a Filter and create a new 'TCustomResponseFilter' to store.

Then, in 'TDictionary<TCustomResponseFilter ,TFilterRecord>', According to the 'TCustomResponseFilter', store the corresponding 'Request.URL', 'CompleteState' initial value, and create a new 'TMemorystream' to prepare for copying data.

Set 'OnFilter := Filter_OnFilter' for each 'TCustomResponseFilter';

Reading data in 'Filter_OnFilter':

if (data_in = nil) then
begin
data_in_read := 0;
data_out_written := 0;
aResult := RESPONSE_FILTER_DONE;

end

else if (data_out <> nil) then
begin
data_in_read := data_in_size;
data_out_written := Min(data_in_read, data_out_size);
if (data_out_written > 0) then
BEGIN
Move(data_in^, data_out^, data_out_written);
if assigned(temprecord.Stream) then temprecord.Stream.Write(data_in^, data_in_size);
END;

if (temprecord.State=1) then
begin
aResult := RESPONSE_FILTER_DONE;
end
else
aResult := RESPONSE_FILTER_NEED_MORE_DATA;
end;


In the 'ResourceLoadComplete' event, locate the corresponding 'TCustomResponseFilter' and 'TFilterRecord' based on 'Request.URL', and record the 'FilterRecord.CompleteState:=1'(indicating ResourceResponse Completed);

Now,I have encountered some difficulties, some of Stream are normal after saving, while others are incorrect after saving,Who can tell me where the problem lies?

What is an accurate way to determine if a resource file transfer has been completed and can be returned as RESPONSE FILTER DONE.

Thanks.
User avatar
salvadordf
Posts: 4057
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to save multiple resource files locally in CEF4

Post by salvadordf »

Hi,

I would first try to copy the streams individually to make sure there are no other problems.

Some times the web server uses compression or it doesn't include a Content-Length HTTP header and the CEF filter fails.

Consider using the URLRequest demo to download those resources.
Post Reply