KBMMW and ExtJS displaying pictures via JSON Base64

Source: Internet
Author: User
Tags base64

Delphi official online began also to introduce the Delphi and ExtJS combination of examples, today I will take the official example of a pirated.

Officially implemented using C++builder and WebBroker.

I use KBMMW to achieve this.

The usual, first to implement the server side, the server is also very simple, is to convert a picture file into Base64, and then encapsulated into a JSON output to the browser.

Direct code:

functionTWEBSRV.GETIMG:string;varmybase64:tbase64encoding;  Myfs:tfilestream; Myss:tstringstream;beginmybase64:=tbase64encoding.Create(0); MYFS:=tfilestream.Create('D:\picture\1.jpg', Fmopenread); Myss:=tstringstream.Create; Trymybase64.    Encode (Myfs,myss); Result:='[{"img": "Data:image/jpeg;base64,'+myss. datastring+'"}]';    finallymybase64.        Free; Myfs.        Free; Myss.    Free; End;End;

Handle the corresponding HTTP GET operation again

functionTwebsrv.performget (clientident:tkbmmwclientidentity;ConstAurl:string;ConstArgs:Array  ofvariant): Variant;varMystringstream:tstringstream; Mimetype,s,scallback:string; Charset,tablename:string;  Qv:tkbmmwhttpqueryvalues; Dataurl,mysql,swhere:string; I:integer;beginQV:=tkbmmwhttpqueryvalues.Create; Dataurl:=args[0]; qv. Asstring:=args[2]; ifLength (Args) <1  Thenkbmmwraiseexception (kbmmw_err_service_http_urlmissing,'Missing URL.'); Try    ifargs[0]='/version'  Then    beginResult:='KBMMW 5.03';    Exit End; ifargs[0]='/getimg'  Then      beginS:=getimg; Scallback:=qv. valuebyname['Callback']; ifScallback<>"'   ThenResult:=scallback+'('+s+')'              ElseResult:=s;      Exit End; ... result:=inheritedPerformget (Clientident,aurl,args); finallyQV.          Free; End;End;

Compile and run, enter http://localhost/getimg in the browser.

Output is normal, server-side, the following design ExtJS.

Add a datastore.

Sets the corresponding property.

Create a corresponding control in the view

and create a button click event

 ext.define (' MyApp.view.MyFormViewController '  ' Ext.app.ViewController '  ' Controller.myform ' , OnButtonClick:  function   (Button, E, eopts) { var  me = this  ;  var  store = Ext.getstore (' myjsonpstore '         ); Store.load ({callback:  function   (Reco RDS) { var  img = me.lookup (' xalionimg ' );            IMG.SETSRC (records[ 0].get (' img ' ));    }        }); }});

OK, publish the app.

Enter http://localhost/index.html inside the browser

Click on the button to display the image.

OK, it's done.

The rest is to learn the knowledge of ExtJS.

KBMMW and ExtJS displaying pictures via JSON Base64

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.