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;
        }
    
  • 相关阅读:
    根据时间段查询数据并按照降序排列
    Json数组(以[ ] 中括号开头)字符串转为json对象
    Java 后台请求第三方系统接口详解
    Map 集合 和 String 字符串相互转换工具类
    并发工具类——CountDownLatch、CyclicBarrier、Semaphore与Exchanger
    AQS相关
    Atomic原子类
    CAS相关
    synchronized关键字相关
    谈谈对volatile关键字的理解
  • 原文地址:https://www.cnblogs.com/lu51211314/p/11322121.html
Copyright © 2011-2022 走看看