Flex 利用 Blazeds上传文件
2010-09-13 20:30
295 查看
用Flex做业务经常会碰到各种类型的文件上传,如FTP上传、Http上传或者WEB服务形式上传,本文说的利用Blazeds上传文件有点类似Http上传,其原理就是客户端发送byte流,然后服务器端flex.messaging.MessageBrokerServlet接收byte流并生成文件。阅读本文最好了解Flex RemoteObject的使用,了解Blazeds的service调用。
1、新建Blazeds的文件上传服务,其实就是一个普通的Java类
2、配置remoting-config.xml文件
3、flex客户端使用FileRefrence、remoteobject组件进行文件上传
1)FileRefrence用于文件选择;
2)remoteobject用户文件上传
1、新建Blazeds的文件上传服务,其实就是一个普通的Java类
Public class FileUpDownloadService{ /** * * <p>Description:文件上传</p> * @param content,文件内容 * @param fileType,文件类型 * @return * @throws Exception * @author Marcus * @date 2010-8-31 下午03:57:10 */ public void uploadFile(byte[] content, String fileType)throws Exception{ File file = new File(文件名+ fileType); //write file FileOutputStream stream = new FileOutputStream(file); stream.write(content); stream.close(); } } |
<destination id="fileUpDownloadService" channels="my-amf"> <properties> <source>FileUpDownloadService</source> <scope>application</scope> </properties> </destination> |
1)FileRefrence用于文件选择;
2)remoteobject用户文件上传
<?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="800" minHeight="600" creationComplete="init()" width="370" height="180"> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; private var file:FileReference = new FileReference(); protected function ro_resultHandler(event:ResultEvent):void { Alert.show("文件上传成功!"); } protected function init():void{ //选择文件后,加载文件 file.addEventListener(Event.SELECT, selectHandler); } private function selectHandler(event:Event):void { file.load(); //加载文件 } protected function ro_faultHandler(event:FaultEvent):void { Alert.show("文件上传失败,"+event.fault.faultString); } protected function btnBrows_clickHandler(event:MouseEvent):void { file.browse(); } protected function btnUpload_clickHandler(event:MouseEvent):void { ro.uploadFile(file.data, file.type); } ]]> </fx:Script> <fx:Declarations> <s:RemoteObject id="ro" destination="fileUpDownloadService" result="ro_resultHandler(event)" fault="ro_faultHandler(event)"/> </fx:Declarations> <s:Button id="btnBrows" click="btnBrows_clickHandler(event)" label="选择文件" x="57" y="60"/> <s:Button id="btnUpload" click="btnUpload_clickHandler(event)" label="上传" x="145" y="60"/> </s:Application> |
相关文章推荐
- 【转】flex利用Blazeds上传文件
- 利用flex+sevlet+fileupload组件实现文件的上传和下载
- Flex中利用FileReference类的browse()和upload()函数选择并上传单个文件到Web服务器
- flex 利用commons-fileupload.jar 上传文件时 乱码解决方式
- 利用flex+sevlet+fileupload组件实现文件的上传和下载
- 利用修改配置文件整合Eclipse和Flex
- 利用put上传文件到服务器
- 利用Flex的Sound类动态显示导入MP3文件时的ID3信息
- 利用xshell从windows上传文件到虚拟机
- 利用Jakarta commons fileupload组件实现多文件上传
- 2014-07-23 利用ASP.NET自带控件实现单文件上传与下载
- Flex 多文件上传带进度条(演示,源码)
- SpringMVC利用MultipartFile进行文件上传
- 利用windows操作系统远程操作linux系统并上传文件
- 利用 Flash 8 上传文件
- 利用scp 远程上传下载文件/文件夹
- 利用SOAP(Webservice)上传文件
- 利用SecureCRT上传、下载文件(使用sz与rz命令)
- 安全培训教程之------上传文件漏洞利用
- 利用Jakarta commons fileupload组件实现多文件上传