欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

flex利用webservice上傳照片實(shí)現(xiàn)代碼

 更新時(shí)間:2014年05月02日 10:13:50   作者:  
這篇文章主要介紹了flex利用webservice上傳照片實(shí)現(xiàn)代碼,需要的朋友可以參考下
WebService端代碼
復(fù)制代碼 代碼如下:

/// <summary>
/// 上傳文件到遠(yuǎn)程服務(wù)器
/// </summary>
/// <param name="fileBytes">文件流</param>
/// <param name="fileName">文件名</param>
/// <returns>字符串</returns>
[WebMethod(Description = "上傳文件到遠(yuǎn)程服務(wù)器.")]
public string UploadFile(byte[] fileBytes, string fileName)
{
try
{
MemoryStream memoryStream = new MemoryStream(fileBytes); //1.定義并實(shí)例化一個(gè)內(nèi)存流,以存放提交上來的字節(jié)數(shù)組。
FileStream fileUpload = new FileStream(Server.MapPath(".") + "\\" + fileName, FileMode.Create); ///2.定義實(shí)際文件對(duì)象,保存上載的文件。
memoryStream.WriteTo(fileUpload); ///3.把內(nèi)存流里的數(shù)據(jù)寫入物理文件
memoryStream.Close();
fileUpload.Close();
fileUpload = null;
memoryStream = null;
return "文件已經(jīng)上傳成功";
}
catch (Exception ex)
{
return ex.Message;
}
}

Flex客戶端代碼
復(fù)制代碼 代碼如下:

<?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>
<!-- 將非可視元素(例如服務(wù)、值對(duì)象)放在此處 -->
<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>

相關(guān)文章

最新評(píng)論