baidu amis开发之input-file

需要导入excel或其他文件时使用。

{
    "label": "导入Excel",
	"align": "right",
	"type": "button",
	"actionType": "dialog",
	"dialog": {
		"title": "导入A程序Excel文件",
		"body": {
			"type": "form",
			"api": "/report/apm/excel/handle",
			"body": [{
			    "type": "input-file",
			    "name": "file",
				"label": "File",
				"accept": ".xlsx",
				"receiver": "/report/apm/excel/upload",
				"drag": true
			}]
		}
	}
}

"api": "/report/apm/excel/handle", 

@ResponseBody
@RequestMapping("/apm/excel/handle")
public String apmExcelHandle(@RequestBody String pageValue) {
	JSONObject parsePageValue = JSON.parseObject(pageValue);
	String file = parsePageValue.getString("file");
	String name = FilenameUtils.getName(file);
	String fileName = Paths.get(System.getProperty("user.dir"), "static", "excel", name).toString();
		
	//
	return pageValue;
}

"receiver": "/report/apm/excel/upload", 是具体调用后端上传文件的接口

@SneakyThrows
@ResponseBody
@RequestMapping("/apm/excel/upload")
public String apmExcelUpload(MultipartFile file, HttpServletRequest request) {
		String path = Paths.get(System.getProperty("user.dir"), "static", "excel").toString();
		File folder = new File(path);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		String name = file.getOriginalFilename();
		file.transferTo(new File(folder, name));
		Map<String, String> data = new HashMap<>(1);
		data.put("value", "/excel/" + name);
		@SuppressWarnings("serial")
		Map<String, Object> rtn = new HashMap<>(3) {
			{
				put("status", 0);
				put("msg", "ok");
				put("data", data);
			}
		};
		return JSON.toJSONString(rtn);
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值