zoukankan      html  css  js  c++  java
  • Flex + .Net从本地选择一个图片上传到服务器

    <mx:TextInput id="TxtFileName" editable="false" width="200"/>
    <mx:Image id="btnBrowser" toolTip="Browser" buttonMode="true" click="fileBrowser(event)"                    
    source="@Embed(source='../assets/icon/icon_browser.png')"/>
    <mx:Button id="btnUpload" label="Upload" buttonMode="true" click="addAttachment(event)" skin="@Embed(source='../assets/skin/btn_skin.gif')" width="80" height="23" />

    新建一个 textiput存储显示文件名和image来做button选取本地图片文件。

    触发的事件代码

    private var curfile:FileReference=new FileReference(); 
    private var browerFlag:Boolean=false;

    private
    function fileBrowser(event:Event):void { var imageTypes:FileFilter = new FileFilter("Images(*.jpg,*.jpeg,*.png,*.gif,*.bmp,*.pdf,*.tif)", "*.jpg;*.jpeg;*.png;*.gif;*.bmp;;*.pdf;*.tif"); curfile.browse([imageTypes]); }

    程序initialize的时候为curfile加监听事件initialize="init()

    private function init():void
    {
      curfile.addEventListener(Event.SELECT,addInTextinput);
    }
    private function addInTextinput(event:Event):void
    {
      TxtFileName.text = curfile.name;
    }

     Button Upload的处理事件

                private function addAttachment(event:Event):void
                {            
                    if(!browerFlag)
                    {
                        return;
                    }
                    if(!curfile.type)
                    {
                        browerFlag=false;
                        TxtFileName.text="";
                        Alert.show(CONSTANT.VoidFileType,CONSTANT.PROJNAME,Alert.OK);
                        return;
                    }
                    var type:String=curfile.type.toLowerCase();
                    if(type&&type!='.jpg'&&type!='.png'&&type!='.bmp'&&type!='.gif'&&type!='.pdf'&&type!='.tif')
                    {
                        browerFlag=false;
                        TxtFileName.text="";
                        Alert.show(CONSTANT.VoidFileType,CONSTANT.PROJNAME,Alert.OK);
                        return;
                    }
                    /* if(curfile.size>4194304) */
                    if(curfile.size>10485760)
                    { 
                        browerFlag=false;
                        TxtFileName.text="";
                        Alert.show(CONSTANT.AttachmentMax,CONSTANT.PROJNAME,Alert.OK);
                        return;
                    }
    
                    //---upload handler--------------
                    var url:String = "UploadFileHandler.aspx?TempFileID="+SysParm.expInfo.ExpenseGUID+"&StaffID="+SysParm.curStaffInfo.StaffID;
                    var reqUrl:URLRequest = new URLRequest(url);
                    
                    curfile.upload(reqUrl);    
            
                }

    怎加两个上传结束以及捕捉错误的事件监听。

                private function init():void
                {
                    curfile.addEventListener(Event.SELECT,addInTextinput);
                    curfile.addEventListener(Event.COMPLETE,uploadComplete);
                    curfile.addEventListener(IOErrorEvent.IO_ERROR,uploadError);
                }    
                private function uploadComplete(event:Event):void
                {    
                    browerFlag=false;
                    ExpenseFunction.removeBusy();
                    Alert.show(CONSTANT.UploadSuccess,CONSTANT.PROJNAME,Alert.OK,null,refreshAttachmentHandler);                
                }    
                private function uploadError(ioError:IOErrorEvent):void
                {
                    browerFlag=false;
                    TxtFileName.text="";
                    Alert.show(CONSTANT.UploadFail,CONSTANT.PROJNAME);
                }
                
                private function refreshAttachmentHandler(event:CloseEvent):void
                {
                    TxtFileName.text="";
                    browerFlag=false;
    
                }
  • 相关阅读:
    [bochs]反编译的代码只能参考参考
    [Linux命令]dd
    exp1orer.exe木马解除方法
    江民公布“密码7005”最新变种技术报告
    广外女生1次惊心动魄的卸载
    [病毒]exp1orer.exe
    [Win2003]禁用关机原因调查
    获得本机IP地址
    一段连接FTP的VC代码
    [Perl]FTP自动上传文件的脚本以及配置文件
  • 原文地址:https://www.cnblogs.com/dangkei/p/3513390.html
Copyright © 2011-2022 走看看