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.
svg cannot be down by Chromium1.DownloadImage
svg cannot be down by Chromium1.DownloadImage
as this:
url:='https://dosrg0qttcg52.cloudfront.net/im ... b2logo.svg';
Chromium1.DownloadImage(url, False, 0, False);
Chromium1DownloadImageFinished :image=nil;
url:='https://dosrg0qttcg52.cloudfront.net/im ... b2logo.svg';
Chromium1.DownloadImage(url, False, 0, False);
Chromium1DownloadImageFinished :image=nil;
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: svg cannot be down by Chromium1.DownloadImage
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.
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.
Re: svg cannot be down by Chromium1.DownloadImage
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?
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?
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: svg cannot be down by Chromium1.DownloadImage
The URLRequest demo does exactly what you want.
Re: svg cannot be down by Chromium1.DownloadImage
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?
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?
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: svg cannot be down by Chromium1.DownloadImage
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.
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.
Re: svg cannot be down by Chromium1.DownloadImage
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]
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]
Re: svg cannot be down by Chromium1.DownloadImage
CEFUrlRequestClientComponent1 should be released or the quest should be released after download and before close?
- salvadordf
- Posts: 4575
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: svg cannot be down by Chromium1.DownloadImage
All downloads should stop before closing the application.
It's not necessary to destroy TCEFUrlRequestClientComponent manually.
If your application keeps copies of the requests then set them to nil before closing the application.
It's not necessary to destroy TCEFUrlRequestClientComponent manually.
If your application keeps copies of the requests then set them to nil before closing the application.
Re: svg cannot be down by Chromium1.DownloadImage
I got it, thank you very much!