mysql - Delphi Firemonkey XE8 - how to correctly send/receive images using DataSnap -


i'm developing android app using delphi firemonkey xe8. need send images server, service has receive , store them.

so far able send , receive simple classes, this:

tcliente = class         private           pcodigo: integer;           pnomerazaosocial: string;           papelidofantasia: string;           pcpfcnpj: string;         public           property codigo: integer read pcodigo write pcodigo;           property nomerazaosocial: string read pnomerazaosocial write pnomerazaosocial;           property apelidofantasia: string read papelidofantasia write papelidofantasia;           property cpfcnpj: string read pcpfcnpj write pcpfcnpj; end; 

the bitmap images stored in sqlite database blob. need send images server and, there, save them in mysql database, in blob fields well.

i need using datasnap.

everything tried far hasn't worked.

i resolved issue in way:

var   strimagem: tmemorystream;   b: tbitmap; begin //create tbitmap of correct size   b := tbitmap.create(rectsign.width div 2, rectsign.height div 2);   b.clear(talphacolorrec.white);  //move source image created tbitmap   if b.canvas.beginscene     try       layoutphoto.paintto(b.canvas, trectf.create(, , b.width, b.height));           b.canvas.endscene;     end;    try //create stream image     strimagem := tmemorystream.create; //load tbitmap     b.savetostream(strimagem); //return cursor of stream beginning     strimagem.position := ;      dm.qmdevice.sql.text := 'update orders set photo = :photo rowid = :rowid';     dm.qmdevice.parambyname('rowid').asinteger := sourcerow; //load query image our stream     dm.qmdevice.parambyname('photo').loadfromstream(strimagem, ftblob);     dm.qmdevice.execsql;     dm.qmdevice.close;   except     on e: exception       toast('unable save photo #7702:'#13#10 + e.message);   end;  //release resources   freeandnil(b);   freeandnil(strimagem); end; 

maybe not elegant, works.


Comments