flex利用webservice上傳照片實(shí)現(xiàn)代碼
WebService端代碼
/// <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)存流,以存放提交上來(lái)的字節(jié)數(shù)組。
FileStream fileUpload = new FileStream(Server.MapPath(".") + "\\" + fileName, FileMode.Create); ///2.定義實(shí)際文件對(duì)象,保存上載的文件。
memoryStream.WriteTo(fileUpload); ///3.把內(nèi)存流里的數(shù)據(jù)寫(xiě)入物理文件
memoryStream.Close();
fileUpload.Close();
fileUpload = null;
memoryStream = null;
return "文件已經(jīng)上傳成功";
}
catch (Exception ex)
{
return ex.Message;
}
}
Flex客戶(hù)端代碼
<?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云盤(pán)/照片/2013Beijing MapOfSubway.jpg"/>
</s:Application>
欄 目:Flex
下一篇:Flex字體加粗問(wèn)題只能對(duì)英文的字體加粗
本文標(biāo)題:flex利用webservice上傳照片實(shí)現(xiàn)代碼
本文地址:http://mengdiqiu.com.cn/a1/Flex/11600.html
您可能感興趣的文章
- 01-11flex調(diào)用webservice中的自定義類(lèi)的方法
- 01-11Flex實(shí)現(xiàn)的上傳攝像頭拍照并將UI保存為圖片
- 01-11Flex字體加粗問(wèn)題只能對(duì)英文的字體加粗
- 01-11Flex控制彈出窗口拖動(dòng)范圍示例代碼
- 01-11flex內(nèi)嵌html網(wǎng)頁(yè)示例代碼
- 01-11Flex中在Tree綁定數(shù)據(jù)后自動(dòng)展開(kāi)樹(shù)節(jié)點(diǎn)的方法
- 01-11Flex彈出窗口請(qǐng)求Action函數(shù)示例
- 01-11Flex中通過(guò)RadioButton進(jìn)行切換示例代碼
- 01-11Flex中TabNavigator設(shè)置Tabs樣式思路及源碼
- 01-11Flex打開(kāi)新窗口將主窗口數(shù)據(jù)傳給子窗口然后返回


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-11flex調(diào)用webservice中的自定義類(lèi)的方法
- 01-11Flex實(shí)現(xiàn)的上傳攝像頭拍照并將UI保存
- 01-11datagrid不可編輯行有關(guān)問(wèn)題的控制方法
- 01-11Flex控制彈出窗口拖動(dòng)范圍示例代碼
- 01-11flex利用webservice上傳照片實(shí)現(xiàn)代碼
- 01-11Flex字體加粗問(wèn)題只能對(duì)英文的字體加
- 01-11Flex中在Tree綁定數(shù)據(jù)后自動(dòng)展開(kāi)樹(shù)節(jié)點(diǎn)
- 01-11flex內(nèi)嵌html網(wǎng)頁(yè)示例代碼
- 01-11Flex中通過(guò)RadioButton進(jìn)行切換示例代碼
- 01-11Flex彈出窗口請(qǐng)求Action函數(shù)示例
隨機(jī)閱讀
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 01-10delphi制作wav文件的方法
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 01-10C#中split用法實(shí)例總結(jié)
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子