Photo handling

Hi,
I got this error now. I don’t know any idea for you.

errorFOB

Hi,

try to check “broken” images in Paint. Can Paint show these images?
If you re-upload “broken” images to DB, will they be shown correctly now ?

Hi,
Yes, you are correct. I open the file by Paint that is an error.

errorJPG

Hi,

Looks like you DB contains some broken images. try to re-upload then and re-check again with Paint/TMS FlexCel

Hi,
I will stop to using Image Sync to DB program. I will using file path in table and Images are keeping in file server. Is it possible add the checking in “DataStreamerWriteFieldValueEx”?

Hi,

You can return blob (= actual image ) instead of string (= file path) in this event…

Hi,
No. I’m return BLOB instead of string path. I think I describe my case not clear. My code is as below.

if (aField.Name = 'SketchPhoto') and (aField.DataType = datBlob) then
begin
  if LeftStr(aDataset.FieldByName('ImagePath').AsWideString,1) <> '\' then
    s := ServerDataModule.PhotoPath + '\' + aDataset.FieldByName('ImagePath').AsWideString
  else
    s := ServerDataModule.PhotoPath + aDataset.FieldByName('ImagePath').AsWideString;

  if fileexists(s) then
  begin
    stream := Binary.Create;
    try
      stream.LoadFromFile(s);
      stream.Position := 0;
      Value := VariantBinaryFromRawBinary(stream);
    finally
      stream.Free;
    end;
  end;
end

Hi,

so you have a case when VariantBinaryFromRawBinary & VariantBinaryToRawBinary break content?

Hi,
Yes. So I think it need to have checking in DataStreamerWriteFieldValueEx that stream is valid or not. If invalid, then skip to return BLOB.

Hi,
I found the solution to solve the stream invalid issue. Thanks.

Hi,

pls share your solution.
it can be useful for other folks.

Hi,
Of course no problem for share my solution. I added the checking that the stream is a valid image format or not. The following is my coding.

procedure TDataService.DataStreamerWriteFieldValueEx(const aDataset: IDADataset;
  const aField: TDAField; var Value: Variant);
var
  s: widestring;
  stream: Binary;
  P : TPicture;
  isValid : boolean;

begin
    if (aField.Name = 'SketchPhoto') and (aField.DataType = datBlob) then
    begin
      isValid := true;
      if LeftStr(aDataset.FieldByName('ImagePath').AsWideString,1) <> '\' then
        s := ServerDataModule.PhotoPath + '\' + aDataset.FieldByName('ImagePath').AsWideString
      else
        s := ServerDataModule.PhotoPath + aDataset.FieldByName('ImagePath').AsWideString;

      if fileexists(s) then
      begin
        stream := Binary.Create;
        try
          stream.LoadFromFile(s);

          P := TPicture.Create;
          try
            try
              P.LoadFromStream(stream);
              except
                isValid := false;
              end
            finally
            P.Free;
          end;

          if isValid = true then
          begin
            stream.Position := 0;
            Value := VariantBinaryFromRawBinary(stream);
          end;
        finally
          stream.Free;
        end;
      end;
    end
end;