# Photo handling

**URL:** https://talk.remobjects.com/t/photo-handling/25200
**Category:** Data Abstract
**Tags:** delphi
**Created:** [August 11, 2021, 7:38am UTC](https://talk.remobjects.com/t/photo-handling/25200 "2021-08-11T07:38:57Z")
**Posts on this page:** 12
**Page:** 2

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 14, 2022, 2:02pm UTC](https://talk.remobjects.com/t/photo-handling/25200/21 "2022-02-14T14:02:55Z")

</div>

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

 ![errorFOB](https://talk.remobjects.com/uploads/default/original/3X/a/5/a50514afaf1d19910b74b666820645c45182ac92.jpeg)

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 14, 2022, 2:12pm UTC](https://talk.remobjects.com/t/photo-handling/25200/22 "2022-02-14T14:12:20Z")

</div>

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 ?

---

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 14, 2022, 2:21pm UTC](https://talk.remobjects.com/t/photo-handling/25200/23 "2022-02-14T14:21:57Z")

</div>

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

 ![errorJPG](https://talk.remobjects.com/uploads/default/original/3X/3/6/36d8596029e4c57b99883a99c75819b0a8abbe73.jpeg)

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 14, 2022, 2:23pm UTC](https://talk.remobjects.com/t/photo-handling/25200/24 "2022-02-14T14:23:43Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 14, 2022, 2:26pm UTC](https://talk.remobjects.com/t/photo-handling/25200/25 "2022-02-14T14:26:53Z")

</div>

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”?

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 14, 2022, 2:29pm UTC](https://talk.remobjects.com/t/photo-handling/25200/26 "2022-02-14T14:29:40Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 14, 2022, 2:31pm UTC](https://talk.remobjects.com/t/photo-handling/25200/27 "2022-02-14T14:31:59Z")

</div>

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
```

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 14, 2022, 2:47pm UTC](https://talk.remobjects.com/t/photo-handling/25200/28 "2022-02-14T14:47:00Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 14, 2022, 2:47pm UTC](https://talk.remobjects.com/t/photo-handling/25200/29 "2022-02-14T14:47:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 15, 2022, 4:33am UTC](https://talk.remobjects.com/t/photo-handling/25200/30 "2022-02-15T04:33:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [February 15, 2022, 8:06am UTC](https://talk.remobjects.com/t/photo-handling/25200/31 "2022-02-15T08:06:39Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![TIMOTHY\_LAM](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/t/76d3ee/32.png) [@TIMOTHY\_LAM](https://talk.remobjects.com/u/TIMOTHY_LAM)
#### Post date: [February 15, 2022, 12:25pm UTC](https://talk.remobjects.com/t/photo-handling/25200/32 "2022-02-15T12:25:17Z")

</div>

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.

```auto
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;

```

[Previous page](https://talk.remobjects.com/t/photo-handling/25200.md?page=1)
