您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

flex利用webservice上传照片实现代码

2024/3/24 20:34:07发布24次查看
webservice端代码
/// <summary> /// 上传文件到远程服务器 /// </summary> /// <param name="filebytes">文件流</param> /// <param name="filename">文件名</param> /// <returns>字符串</returns> [webmethod(description = "上传文件到远程服务器.")] public string uploadfile(byte[] filebytes, string filename) { try { memorystream memorystream = new memorystream(filebytes); //1.定义并实例化一个内存流,以存放提交上来的字节数组。 filestream fileupload = new filestream(server.mappath(".") + "\\" + filename, filemode.create); ///2.定义实际文件对象,保存上载的文件。 memorystream.writeto(fileupload); ///3.把内存流里的数据写入物理文件 memorystream.close(); fileupload.close(); fileupload = null; memorystream = null; return "文件已经上传成功"; } catch (exception ex) { return ex.message; } }
flex客户端代码
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" minheight="600" creationcomplete="application1_creationcompletehandler(event)"> <fx:script> <![cdata[ import mx.controls.alert; import mx.events.flexevent; import mx.graphics.codec.jpegencoder; import mx.rpc.events.faultevent; import mx.rpc.events.resultevent; protected function application1_creationcompletehandler(event:flexevent):void { var width :int = imgid.width; var height :int = imgid.height; var bitmapdata:bitmapdata =new bitmapdata(width,height); bitmapdata.draw(imgid); var bytearr:bytearray = bitmapdata.getpixels(new rectangle(0,0,width,height)); var bytearr123:bytearray =new jpegencoder().encodebytearray(bytearr,width,height); webservice.uploadfile(bytearr123,"123.png"); } protected function webservice_faulthandler(event:faultevent):void { alert.show(event.fault.tostring()); } protected function webservice_successhandler(event:resultevent):void { alert.show(event.result.tostring()); } ]]> </fx:script> <fx:declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> <s:webservice id="webservice" wsdl="http://10.19.1.48/upimg/service1.asmx?wsdl" fault="webservice_faulthandler(event)"> <s:operation name="uploadfile" result="webservice_successhandler(event)"></s:operation> </s:webservice> </fx:declarations> <mx:image id="imgid" x="186" y="103" width="583" height="397" source="file:/g:/360云盘/照片/2013beijing mapofsubway.jpg"/> </s:application>
更多flex利用webservice上传照片实现代码。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product