佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > flex利用webservice上傳照片實現(xiàn)代碼

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

熱門標(biāo)簽:鐵路電話系統(tǒng) 美圖手機 銀行業(yè)務(wù) 網(wǎng)站文章發(fā)布 智能手機 服務(wù)器配置 檢查注冊表項 呼叫中心市場需求
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.定義并實例化一個內(nèi)存流,以存放提交上來的字節(jié)數(shù)組。
FileStream fileUpload = new FileStream(Server.MapPath(".") + "\\" + fileName, FileMode.Create); ///2.定義實際文件對象,保存上載的文件。
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ù)、值對象)放在此處 -->
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>

標(biāo)簽:紅河 樂山 滄州 上海 河南 新疆 沈陽 長治

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《flex利用webservice上傳照片實現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    卫辉市| 沂源县| 江城| 永定县| 湖口县| 平阳县| 中西区| 马公市| 浦北县| 固镇县| 兴仁县| 宁波市| 新兴县| 宁明县| 淮安市| 西宁市| 上高县| 九龙县| 肥乡县| 庐江县| 新郑市| 桃源县| 常宁市| 北流市| 南阳市| 孝昌县| 县级市| 娄底市| 咸丰县| 天全县| 米林县| 资阳市| 谷城县| 淮阳县| 镇赉县| 阳西县| 泽州县| 长沙市| 大姚县| 西城区| 深州市|