zoukankan      html  css  js  c++  java
  • 使用代码上传文件示例

    public Map<String, Object> sendGrantToCrm(String custNo, String cardNo, String path, String fileName) {
    
            FileSystemResource fileSystemResource = new FileSystemResource(path + fileName);
            MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
            Map<String, Object> resultMap = new HashMap<>();
            try {
                InputStream is = new BufferedInputStream(new FileInputStream(path + fileName));
                String md5 = DigestUtils.md5Hex(IOUtils.toByteArray(is));
                IOUtils.closeQuietly(is);
    
                String crmUrl = EurekaServer.CRM + "/app/crm/cust/arch/upload?custNo=" + custNo
                        + "&cardNo=" + cardNo + "&archType=1" + "&fileName=" + fileName + "&md5=" + md5;
                HttpHeaders headers = new HttpHeaders();
                paramMap.add("file", fileSystemResource);
                HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(paramMap, headers);
                ResponseEntity entity = restTemplate.exchange(crmUrl, HttpMethod.POST, httpEntity, Map.class);
                Map<String, Object> crmRetMap = (Map<String, Object>) entity.getBody();
                logger.info("授权书发送CRM:entity=" + crmRetMap);
    
                if (!"00000".equals(((Map<String, Object>) crmRetMap.get("head")).get("retFlag"))) {
                    resultMap.put("retCod", "00001");
                    resultMap.put("retMsg", ((Map<String, Object>) entity.getBody()).get("retMsg"));
                    return resultMap;
                }
            } catch (Exception e) {
                logger.error("文件上传CRM异常!" + e.getMessage());
                resultMap.put("retCod", "00002");
                resultMap.put("retMsg", "文件上传CRM异常!");
                return resultMap;
            }
            resultMap.put("retCod", "00000");
            return resultMap;
        }
    
  • 相关阅读:
    juicer 语法
    mvc 理解
    php 之 trait
    阿里P8面试官:如何设计一个扛住千万级并发的架构?
    建模
    镜像推送时出现 server gave HTTP response to HTTPS client 问题的解决方法
    git在线练习网站
    ubuntu 20.04 LTS 更换阿里云源
    Proxmox VE(Proxmox Virtual Environment)制作优盘(U盘)启动盘的教程说明方法
    KubeSphere部署Nacos集群
  • 原文地址:https://www.cnblogs.com/lu51211314/p/11322121.html
Copyright © 2011-2022 走看看