flex上传文件

前端代码:
public function confirm():void{
		var file:FileReference = new FileReference();
		file.download(new URLRequest(PdpRequestUrl.exportPayment+"?startTime="+startTime.text+"&endTime="+endTime.text),"支付记录.xls");
		var alert:Alert;
		file.addEventListener(Event.SELECT,function(event:Event):void{
			alert = Alert.show("正在导出中,请稍后...","提示");
		});
				
		file.addEventListener(Event.COMPLETE, function(event:Event):void{
			PopUpManager.removePopUp(alert);
			Alert.show("导出成功!","提示");
			close();
		});
}
 
后台用grails写的:
 def exportService;
def exportPayment(){
        log.info("导出支付记录start.....................")
        response.contentType = 'application/vnd.ms-excel'
        response.setHeader('Content-disposition', 'attachment;filename=transinfo.xls')
        def queryParams = {
            if (params.startTime && params.endTime) {
                if (params.startTime > params.endTime) {
                    throw new LogicException("开始时间不能大于结束时间");
                }
            }
            if (params.startTime?.trim()) {
                ge("createTime", AppDateUtils.toDate(params.startTime.trim(), AppDateUtils.yyyyMMdd))
            }
            if (params.endTime?.trim()) {
                lt("createTime", AppDateUtils.addDay2Date(AppDateUtils.toDate(params.endTime.trim(), AppDateUtils.yyyyMMdd), 1))
            }
        }
        def list = Payment.createCriteria().list(queryParams);
        List<Map> result = new ArrayList<Map>()
        list.each { Payment payment ->
            Map bean = [:];
            bean.paymentNum = payment.paymentNum;
            bean.amount = payment.amount/100;
            bean.channelName = payment.channelInfo.channelName;
            bean.createTime = AppDateUtils.toString(payment.createTime,AppDateUtils.yyyyMMddHHmmss);
            bean.memo = payment.memo;
            result.add(bean);
        }
        List fields = [
                'paymentNum',
                'channelName', 'amount',
                'createTime', 'memo'
                ]
        Map labels = [
                'paymentNum': '交易流水号',
                'channelName': '渠道', 'amount': '支付金额',
                'createTime': '支付时间', 'memo': '描述'
                ]

        Map parameters = [title: '支付记录', 'column.widths': [0.2, 0.15, 0.15, 0.2, 0.2]]
        try {
            exportService.export('excel', response.outputStream, result, fields, labels, [:], parameters);
        } catch (Exception e){
            throw new LogicException("导出失败!");
        }
        log.info("导出支付记录end.....................")
    }
 

你可能感兴趣的:(Flex)