`
windmark
  • 浏览: 30602 次
社区版块
存档分类
最新评论

Flex AMF Upload Demo

    博客分类:
  • Flex
 
阅读更多

java端:写一个名为ZhuaTuSerlvet的Serlvet,这个类需要用到flex-messaging-core.jar这个包.
    需要用到SerializationContext,ASObjectAmf3Input,Amf3Output这几个类(
   

 import flex.messaging.io.SerializationContext;
    import flex.messaging.io.amf.ASObject;
    import flex.messaging.io.amf.Amf3Input;
    import flex.messaging.io.amf.Amf3Output;
    )

 


    其中doPost方法的内容如下:

public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

             Amf3Input amf3in = new Amf3Input(context);  
            Amf3Output amf3out = new Amf3Output(context);  
            ByteArrayOutputStream stream = new ByteArrayOutputStream();  
            amf3in.setInputStream(new DataInputStream(request.getInputStream()));  
            
            String uploadPath = "c:/";
        response.setContentType("application/octet-stream");
            InputStream is = request.getInputStream();
            try {
             int size = 0;
             byte[] b = new byte[100000];
             byte[] tmp = new byte[100000];
             int len = 0;
             long time = System.currentTimeMillis();
             File file = new File(uploadPath + time + ".png");
             DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
             while ((len = is.read(tmp)) != -1) {
                 dos.write(tmp, 0, len);
                 size += len;
             }
             dos.flush();
             dos.close();
             
             //System.out.println("图片的保存路径是: " + file.getAbsolutePath());
                 
             //返回文件保存路径
             ASObject message1 = new ASObject(); 
             //像HashMap一样设置变量
              message1.put("path", file.getAbsolutePath());  
              amf3out.setOutputStream(stream);  
             amf3out.writeObject(message1);  
             amf3out.flush();  
             response.getOutputStream().write(stream.toByteArray());  
            } catch (IOException e) {
                    e.printStackTrace();
            }
    }

 


flex端:
   

 /**
    * 上传图片到服务器
    */ 
    public function uploadFile():void{
        var request:URLRequest = new URLRequest("http://192.168.3.139:8989/1test/servlet/ZhuaTuSerlvet");
        loader = new URLLoader();
        
        request.method=URLRequestMethod.POST;
        request.contentType = "application/octet-stream";
        request.data = new JPEGEncoder(85).encode(imgBD);
        //以二进制形式通信.不加此行会报空指针异常
        loader.dataFormat = URLLoaderDataFormat.BINARY;  
        loader.load(request);
        
        loader.addEventListener(Event.COMPLETE,onComplete);
        //loader.addEventListener(IOErrorEvent.IO_ERROR,onError);
        //loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecurityError);
    }

    /**
     * 上传成功 
     */            
    public function onComplete(event:Event):void{
        switch(event.type){  
            case Event.COMPLETE:  
                var bytes:ByteArray = loader.data as ByteArray;  
                var obj:Object = bytes.readObject();  
                //遍历所有参数
                //for(var key:* in obj){  
                    //Alert.show(key+":"+obj[key]);  
                //}  
                Alert.show("上传成功,图片保存在 " + obj["path"]);  
                break;  
        
        }  
    }

 

开源组件:http://code.google.com/p/flexupload/

 Sample:http://www.chaosm.net/blog/2011/08/14/upload-multiple-files-in-adobe-air-with-zend-amf-and-flex/

 

分享到:
评论

相关推荐

    AMF.rar_FluorineFx_FluorineFx amf_amf__flex_flex amf

    Flex AMF通讯,主要用于初学者配置FluorineFx.net服务端

    AMF抓取flex页面数据

    抓取AMF协议的flex页面,支持模拟登录和页面抓取。

    flex与amf

    flex与java通信

    flex-messaging-core-amf1.7

    flex-messaging-core-amf1.7

    flex与java远程传值demo

    一个java web项目模块,一个flex项目模块,web项目发布到tomcat,flex通过BlazeDS远程服务来调用java服务提供的方法,实现了flex前端与java后台服务的数据交互。

    amf-php flex插件

    这是一个flex的lib库,方便开发者迅速开展amf连接操作。

    Flex + Zend AMF + MYSQL + WAMP 新手指南

    NULL 博文链接:https://sjkgxf7191.iteye.com/blog/572828

    AMF数据分析器_V22

    功能: 支持AS3的ByteArray序列化...支持Flex外部化类的AMF编码、解码。 支持解压还原LZMA算法压缩过的SWF文件(文件头三字节为:ZWS的 *.SWF文件)。 为方便想了解AMF格式及封包的坛友分析解码AMF数据资料使用。

    AMF格式文件

    Adobe Flex BlazeDS AMF File Format 熟悉下这个东西后,可以自己实现BlazeDS的前端和后端,至少也能在浏览器里的F12开发环境里搞明白AMF的内容了。

    开源amf协议解析封装

    amf c# flex服务端协议解析和封装。

    thinkphp_amf

    thinkphp_amf的一个简单demo

    跟我StepByStep学FLEX教程-王一松.pdf

    1 26 跟我StepByStep学FLEX教程------AMF 1 27 跟我StepByStep学FLEX教程------Demo12之FLEX和Spring整合 1 28 跟我StepByStep学FLEX教程------访问数据库之JDBCTemplate 1 29 跟我StepByStep学FLEX教程------...

    AMF.NET 文件极小的开源AMF解析库

    AMF开源FluorineFx文件太大 对于只需要序列化和反序列化AMF数据流的朋友,这个库是不错的选择 支持.net 1.1和2.0+

    flex jar包(很全)

    【flex的jar包,项目中的jar包,比较多,但是有些没用,我都放进去了大家自己取舍吧 】 【2010-12-24】提交过一版,此次加入两个官方更新的jar包。 【2011-06-14】更新:flex-messaging.jar和flex-messaging-common....

    AMF移植代码

    移植RMTP 看看效果 amf flex

    AMF编码解码演示版

    AMF编码解码演示版,易语言类。文档及demo.

    RTMP协议中AMF的定义.pdf

    《RTMP协议中AMF的定义》,原名《TheAMF》英文版本。 内容简介: The AMF object is used for the sending and receiving of all video/audio data. After the initial handshake, all objects sent use the AMF ...

    AMF1.0(AMP).zip

    AMF1.0(AMP).zip 代码

    易语言amf解析构造

    易语言amf解析构造源码,amf解析构造,分析amf,取短整数_字节集,时间到双精度,到时间_双精度,取整数_字节集,integer_字节集,取双精度_字节集,amf3型数据,十六进制转字节集,分析数据段,解析amf数据,解析amf3数据,Utf8转...

    AMF AMD Radeon硬件编码ffmpeg编译库源码

    Advanced Media Framework AMF AMD Radeon硬件编码ffmpeg编译库源码 The AMF framework is compatible with most recent Radeon GPUs starting with the Southern Islands family and APUs of the Kabini, Kaveri, ...

Global site tag (gtag.js) - Google Analytics