That works well. Now I am failing to load the image from the blob-field.
I tried to load the blob-content in a TMemoryStream by
MStream:=DataModule_Client.DataSet_NewLogo.CreateBlobStream( (DataModule_Client.DataSet_NewLogo.FieldByName('logo') as TBlobField), bmRead)
But this methode is not available for the TWebDataSet
I tried to store the image as string (Base64Image) and tried on that ways:
Img_Logo1.URL:= 'data:image/png;base64,'+Img_Base64; (Img_Base64 includes the Base64Imgae-String)
or with an TFNCImage
FImg1.Bitmap.LoadFromURL(Img_Base64);
thanks for answering. I am sorry, but I am not able to fix it. I tried it on that way, also.
There is a Record in the DataSet, but I cann not handle it.
'procedure TForm_TVclient_Main.WebButton8Click(Sender: TObject);
begin
Img_Logo2.URL:=DataModule_Client.DataSet_NewLogo.FieldByName('logo').AsString;
WebMemo2.Lines.Add(IntToStr(DataModule_Client.DataSet_NewLogo.FieldByName('logo_id').AsInteger)); //Check if data in DataSet yes
WebMemo2.Lines.Add(Img_Logo2.URL); //Check if data in DataSet no
WebMemo2.Lines.Add(IntToStr(DataModule_Client.DataSet_NewLogo.FieldByName('logo_id').AsInteger)); //Check if data in DataSet yes
end;'
It looks like that the blob-field is empty. but on the db I can see a value of 1.696 byte.
Can you please support me, I tried to fix that the last days?
Many thanks Patrick
I cannot see an issue here.
Is the active record the correct record you look for when you access it as
DataModule_Client.DataSet_NewLogo.FieldByName('logo').AsString;
?
I have a partial success: It works with a string-field, but not with a blob-field.
I save the same value in a string-field and in a blob-flield:
'function TDataModule_Client.Save_NewLogo(Logo_string: string): boolean;
begin
Try
if DataSet_NewLogo.State=dsBrowse then
DataModule_Client.DataSet_NewLogo.Insert;
DataSet_NewLogo.FieldByName('company_id').AsInteger:=DataSet_NewCompany.FieldByName('company_id').AsInteger;
//DataSet_NewLogo.FieldByName('logo_id').AsInteger:=8;
if Logo_string<>'' then begin
DataSet_NewLogo.FieldByName('logo').AsString:=Logo_string;
DataSet_NewLogo.FieldByName('logo_string').AsString:=Logo_string;
end;
DataSet_NewLogo.Post;
DataSet_NewLogo.ApplyUpdates;
Result:= true;
Except
Result:= false;
End;
end;
If I load the image with the sting-field, it works:
procedure TForm_TVclient_Main.Btn_LogoLoadClick(Sender: TObject);
var Img_Base64: string;
begin
DataModule_Client.DataSet_NewLogo.Cancel;
DataModule_Client.DataSet_NewLogo.Open;
Img_Base64:='data:image/png;base64,'+DataModule_Client.DataSet_NewLogo.FieldByName('logo_string').AsString;
Img_Logo2.URL:=Img_Base64;
WebMemo1.Lines.Text:=Img_Base64;
end;
If I do exactly the same with the blob-field I get now record content:
procedure TForm_TVclient_Main.Btn_LogoLoadBlobClick(Sender: TObject);
var Img_Base64: string;
begin
DataModule_Client.DataSet_NewLogo.Cancel;
DataModule_Client.DataSet_NewLogo.Open;
Img_Base64:='data:image/png;base64,'+DataModule_Client.DataSet_NewLogo.FieldByName('logo').AsString;
Img_Logo2.URL:=Img_Base64;
WebMemo2.Lines.Text:=Img_Base64;
end;
Do you have an idea. I would like to realize it with a blob...
It looks like that the string in the blob-field (i changed it to LongText) is different to the VARChar field. The size is different (LongText=27.688 byte and VARCHAR=18.458 byte) and the signs are also different.
I connect the app via xdata server to the database. I have a unit with all database fields for the xdata app created by the TMS Data Moduler. Maybe it is coursed there...
I am nearly sure that my issue is not coursed in the DB_Unit which is created by the TMS Data Moduler. It seems that it is coursed in the field-definition of the TWebDataSet.
Ichanged the field-type of logo_sting to LongText, also. But I did not changed the data-field-definition. Then it worked. I tried to change the definition of the field logo also, but it didn't work.
Then I was so brilliant and changed the name of the field logo in the database, created a new DB_Unit, deleted the field logo from the TWebDataSet and definied a new field as string.
After that, both fields can not store the value of the image_string. I do not know, what I can do know... I can not reproduce it...
If you could send a project that reproduces the issue, that would be helpful.
In any case, if you are always going to save text content in the blob field, add the attribute DBTypeMemo (or DBTypeWideMemo) to your mapping so Aurelius knows it's a memo field:
You can't just get binary data as string.
You need to get it as binary data and encode it as base64 string.
The unit WEBLib.Utils has methods for converting binary arrays to base64 string
Or, more convenient is to store the value already server side as base64 in the DB and then you can directly use it client side.
then you say is more efficient to read image directly from DB in Base64 format ? ok i can store the image in base64 format in a Blob text field ? this procedure go fine to do this ?
Did you do the effort to take the string returned from your dataset field and verify with a tool like: Base64 to Image | Base64 Decode | Base64 Converter | Base64
that the data URL you assign to the image is a valid image data URL?
If it isn't, well, then there is something wrong with the data in the DB field and you should check that.
Bruno i said all go fine only if in my entity i use String type NOT blob ok ? and it is your bug i think or my mistake ...
Then how is the maximum size of a string ? i used to test 21800 but its enougth ? if i have large images big images what size i can use ?