Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Error on sending or retrieving image using JSON "Bitmap image is not valid"


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Aug 9, 2016 7:15 PM Last Post By: Philip Frank
Fuandi Hartanto

Posts: 18
Registered: 1/12/15
Error on sending or retrieving image using JSON "Bitmap image is not valid"  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 14, 2016 1:51 AM
HI,

I'm using delphi 10 Seattle, and currently having problem with sending/retrieving image from mobile phone to datasnap server and save it into db.
After I load the image, I got an error saying "Bitmap image is not valid".
So I'm not sure whether the sending or retrieving or saving into db is wrong.
Can someone help me on this case ?

Here are the snippet of my source code.
Client code :
ja := TJSONArray.Create;
jo := TJSONObject.Create;
mStream := TMemoryStream.Create;
try
image1.Bitmap.SaveToStream(mStream);
mStream.Position := 0;
jo.AddPair('photoid', 'test1');
jo.AddPair('file', TIdEncoderMIME.EncodeStream(mStream));

ja.AddElement(jo);
finally
mStream.Free;
end;

RESTRequestPhoto.Params.Clear;
RESTRequestPhoto.Params.AddItem('jsondata', ja.ToString(), pkGETorPOST, [], ctAPPLICATION_JSON);
RESTRequestPhoto.method := rmPost;
RESTRequestPhoto.Execute;


Server Code :

function TDeliveryOrderMethod.updateUploadPhoto(Data:TJSONArray): String;
var mStream: TStream;
begin
mStream := TMemoryStream.Create;
try

TIdDecoderMIME.DecodeStream(
(TJSONObject(Data.Get(0)).Get('file').JsonValue as TJSONString).Value,mStream);
mStream.Position := 0;

with fdqryPhoto do begin
close;
sql.Clear;
sql.Add('select * from photo_tbl');
open;
end;
fdqryPhoto.Insert;
TBlobField(fdqryPhoto.FieldByName('photo')).LoadFromStream(mStream);
fdqryPhoto.Post;

end;

Philip Frank

Posts: 47
Registered: 4/13/97
Re: Error on sending or retrieving image using JSON "Bitmap image is not valid"  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 9, 2016 7:15 PM   in response to: Fuandi Hartanto in response to: Fuandi Hartanto
Fuandi Hartanto wrote:
HI,

I'm using delphi 10 Seattle, and currently having problem with sending/retrieving image from mobile phone to datasnap server and save it into db.
After I load the image, I got an error saying "Bitmap image is not valid".
So I'm not sure whether the sending or retrieving or saving into db is wrong.
Can someone help me on this case ?

I've been trying to resolve the same problem. As it turns out, as long as you're not getting an error while transferring the BLOB data your problem is probably not with the data itself, but that it's not a BMP file! Here's a useful page from the docs on file formats typically supported by various operating systems:
http://docwiki.embarcadero.com/Libraries/XE8/en/FMX.Graphics.TBitmapCodecManager

You'll notice BMP is not supported by either iOS or Android. Once I learned that, I discovered that the image files in my database were PNG files, not BMP. Using a hex editor to look at the data was a further confirmation that the data were PNG files.

Take another look and see if your situation isn't the same.

Phil
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02