svg cannot be down by Chromium1.DownloadImage

Post Reply
coater
Posts: 89
Joined: Sat Sep 29, 2018 1:51 pm

svg cannot be down by Chromium1.DownloadImage

Post by coater » Tue May 19, 2020 12:32 pm

as this:
url:='https://dosrg0qttcg52.cloudfront.net/img/site_logo/5c8a4e6a165b2logo.svg';
Chromium1.DownloadImage(url, False, 0, False);

Chromium1DownloadImageFinished :image=nil;

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

Re: svg cannot be down by Chromium1.DownloadImage

Post by salvadordf » Tue May 19, 2020 12:48 pm

Hi,

ICEFImage seems to support PNG, JPEG and BMP formats only.

Use TChromium.StartDownload or use the code in the URLRequest demo to download SVG files.

coater
Posts: 89
Joined: Sat Sep 29, 2018 1:51 pm

Re: svg cannot be down by Chromium1.DownloadImage

Post by coater » Wed May 20, 2020 7:37 am

Thank you very much!
I want to encode svg or png to base64 without the need to save files.
Is it possible to use a memorystream or another stream to get a svg/png before download?

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

Re: svg cannot be down by Chromium1.DownloadImage

Post by salvadordf » Wed May 20, 2020 8:16 am

The URLRequest demo does exactly what you want.

coater
Posts: 89
Joined: Sat Sep 29, 2018 1:51 pm

Re: svg cannot be down by Chromium1.DownloadImage

Post by coater » Wed May 20, 2020 10:39 am

I saw the code, but I still have questions
Is it possible to download urls by CEFUrlRequestClientComponent at the same time?
In that code url only can be assigned in DownloadData, so if I create some addrequests, how to deal with urls in DownloadData?

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

Re: svg cannot be down by Chromium1.DownloadImage

Post by salvadordf » Thu May 21, 2020 8:19 am

If I understand you correctly, you want to create several requests to download several URLs.

It would be interesting to use 1 TCEFUrlRequestClientComponent to handle several ICefUrlRequest instances.
In order to do that we would need to have a way to recognize each ICefUrlRequest instance in the TCEFUrlRequestClientComponent.OnDownloadData event.

I tried for a short time long ago and I couldn't find a way to recognize the different ICefUrlRequest instances in created in TCEFUrlRequestClientComponent.OnCreateURLRequest

Calling SomeInterface.SameAs(OtherInterface) didn't work at that time but you can still add a custom HTTP header to the request when you create it and check if that header exists with "request.request.GetHeaderByName" in the TCEFUrlRequestClientComponent.OnDownloadData event.

coater
Posts: 89
Joined: Sat Sep 29, 2018 1:51 pm

Re: svg cannot be down by Chromium1.DownloadImage

Post by coater » Mon May 25, 2020 8:18 am

The browser receive a message from JS and run the function GetImgBase64Fun. So it is difficult to add a custom HTTP header to the request every time.
So I use TCriticalSection(ImageCS: TCriticalSection) to ensure the CEFUrlRequest download images one by one.




[code]
procedure MyDownImgTobase( aParam : Pointer); stdcall; // : string : PImageRec Parameter
//Function MyDownImgTobase( aParam : Pointer):string;stdcall;
var
// Id: Dword;
aImageRec2: TImageRec;
tempstr, fileexstr: string;
i:integer;
//base64: TBase64Encoding;
m2: TStringStream;
begin
ImageCS.Enter;

IfCEFUrlRequestCreateURLRequest := False;
IfCEFUrlRequestRequestComplete := False;
IfCEFUrlRequestRequestSucess := False;
i:= 0;
aImageRec2.order := TImageRec(aParam^).order ;
aImageRec2.edittype := TImageRec(aParam^).edittype ;
aImageRec2.SpeciName := TImageRec(aParam^).SpeciName ;
aImageRec2.url := TImageRec(aParam^).url; //aParam.url;
aImageRec2.basestr := TImageRec(aParam^).basestr ;
FImgStream := TMemoryStream.Create;
IinformSearchFrm.CEFUrlRequestClientComponent1.AddURLRequest;

repeat
Sleep(500);
i:=i+1;
until (IfCEFUrlRequestRequestComplete or (i>60));

if IfCEFUrlRequestRequestSucess then
begin
try
m2 := TStringStream.Create;
FImgStream.Position := 0;
tempstr := BaseImage(FImgStream);
fileexstr:= '';
if (ansipos('.',aImageRec2.url)>0) then
begin
fileexstr:= RightStr (aImageRec2.url, Length(aImageRec2.url) - LastPos('/',aImageRec2.url));
if (ansipos('.',fileexstr)>0) then
fileexstr := RightStr (fileexstr, Length(fileexstr) - LastPos('.', fileexstr));
end;
if fileexstr = '' then fileexstr := CheckImgType(FImgStream);
finally
//base64.Free;
m2.Free;
FImgStream.Free;
end;
tempstr:= aImageRec2.SpeciName + ' = ' + DealJsSpeChar('data:image/'+ fileexstr + ';base64,'+tempstr) ;
TFrm.Chromium1.Browser.MainFrame.ExecuteJavaScript(tempstr, TFrm.Chromium1.Browser.MainFrame.Url, 0);
end;

ImageCS.Leave;

end;

function TFrm.GetImgBase64Fun( aurl: TImageRec ): Boolean;
var //aImageUB :ImageUB;
Id: Dword;
aHandle : THandle;
//aImageRec: TImageRec;
begin
Result := false;
Id:=0;
aHandle := 0;
aHandle := CreateThread(nil, 0, @MyDownImgTobase, @aImageRec, 0, Id ); // BeginThread
if aHandle>0 then
Result:=true;
end;
[/code]

Post Reply