濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > flex利用webservice上傳照片實(shí)現(xiàn)代碼

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

熱門標(biāo)簽:無(wú)錫電銷外呼系統(tǒng)代理 地圖標(biāo)注多家店 什么行業(yè)需要電話機(jī)器人 南昌crm外呼系統(tǒng)如何 廣州ai外呼系統(tǒng)業(yè)務(wù) 外呼系統(tǒng)號(hào)碼顯示 天津企業(yè)外呼系統(tǒng)代理商 車載電話機(jī)器人 中山外呼系統(tǒng)中間件
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)存流,以存放提交上來(lá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>

標(biāo)簽:泰州 呂梁 仙桃 滄州 欽州 佛山 海西 攀枝花

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《flex利用webservice上傳照片實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  flex,利用,webservice,上傳,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《flex利用webservice上傳照片實(shí)現(xiàn)代碼》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于flex利用webservice上傳照片實(shí)現(xiàn)代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    台江县| 西藏| 志丹县| 建德市| 宜章县| 郑州市| 耒阳市| 赣州市| 闻喜县| 桃园市| 娄底市| 莲花县| 疏附县| 水城县| 苗栗县| 松溪县| 尉犁县| 湖北省| 阿合奇县| 青田县| 拉萨市| 长垣县| 靖边县| 湖口县| 溧阳市| 海阳市| 铅山县| 江山市| 绩溪县| 锡林郭勒盟| 柳河县| 邓州市| 肥西县| 博湖县| 临邑县| 广水市| 阿合奇县| 佛山市| 合阳县| 当涂县| 大冶市|