Flex3上传附件至服务器

private var file:FileReference;

private var displayTypes:FileFilter=new FileFilter("Excel文件(*.xls)","*.xls");
private var fileFilter:Array=new Array(displayTypes);

//初始化

file = new FileReference();
file.addEventListener(Event.SELECT, onSelect);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,xmlComplete);

//浏览本地文件

file.browse(fileFilter);

 private function onSelect(e: Event): void
{
            Alert.show("上传 " + file.name + " (共 "+Math.round(file.size)+" 字节)?",
                            "确认上传",Alert.YES|Alert.NO,null,proceedWithUpload);                        

}

 private function proceedWithUpload(e:CloseEvent): void
 {
             if (e.detail == Alert.YES)
             { 
              var upLoadUrl:String=spExcelUrl;
                var request:URLRequest = new URLRequest(upLoadUrl);
                CursorManager.setBusyCursor();
                file.upload(request);
                
                //loading
               swfLoader.source="assets/2/loading.swf";
               swfLoader.alpha=0.8;
               swfLoader.isPopUp=true;
               mx.managers.PopUpManager.addPopUp(swfLoader, DisplayObject(parentApplication), true);
               mx.managers.PopUpManager.centerPopUp(swfLoader);  
             }
 }

 

    //c#

    string uploadFolder = "upload"; // 上传文件夹
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpFileCollection files = Request.Files;

        if (files.Count == 0)
        {
            Response.Write("请勿直接访问本文件");
            Response.End();
        }

        string path = Server.MapPath(uploadFolder);

        // 只取第 1 个文件
        HttpPostedFile file = files[0];

        if (file != null && file.ContentLength > 0)
        {
            // flash 会自动发送文件名到 Request.Form["fileName"]
            string savePath = path + "/" + Request.Form["fileName"];
            file.SaveAs(savePath);
            getXml(savePath);
            System.IO.File.Delete(savePath);
        }

    }

分类:  Flex3

本文转自Lei Zhang的博客博客园博客,原文链接:http://www.cnblogs.com/threestone/archive/2010/04/18/1714794.html,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 Element UI 的文件上传组件,需要先引入 Element UI 库和相关样式文件。然后在代码中使用 el-upload 标签即可。 示例代码如下: ```html <template> <el-upload class="upload-demo" action="/upload" :on-preview="handlePreview" :on-remove="handleRemove" :before-upload="beforeUpload" :file-list="fileList" :auto-upload="false"> <el-button slot="trigger" size="small" type="primary">选取文件</el-button> <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传服务器</el-button> <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div> </el-upload> </template> <script> export default { data() { return { fileList: [] }; }, methods: { handlePreview(file) { console.log(file); }, handleRemove(file, fileList) { console.log(file, fileList); }, beforeUpload(file) { const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'; const isLt2M = file.size / 1024 / 1024 < 2; if (!isJPG) { this.$message.error('上传头像图片只能是 JPG/PNG 格式!'); } if (!isLt2M) { this.$message.error('上传头像图片大小不能超过 2MB!'); } return isJPG && isLt2M; }, submitUpload() { this.$refs.upload.submit(); } } }; </script> <style> .upload-demo { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; } </style> ``` 在这个示例中,我们使用了 el-upload 组件,并设置了一些属性和方法: - action:上传文件的地址。 - on-preview:点击文件列表中已上传的文件时触发的方法。 - on-remove:点击删除按钮时触发的方法。 - before-upload:上传文件之前的校验方法。 - file-list:已上传的文件列表。 - auto-upload:是否自动上传文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值