zoukankan      html  css  js  c++  java
  • 上传文件

    /**
         * 上传文件
         * @param files    文件
         */
        @PostMapping("upload")
        @ApiOperationSupport(order = 1)
        @ApiOperation(value = "上传文件", notes = "传入文件")
        public R<List<OaAttachment>> upload(@RequestParam List<MultipartFile> files) {
            List<OaAttachment> list = new ArrayList<OaAttachment>();
            //String dirPath = getRequest().getServletContext().getRealPath("/") +"uploadFile/";
            String dirPath = "E:/attachment/oa/uploadFile/" ;
            File dir = new File(dirPath);
            if (!dir.exists()) {
                dir.mkdir();
            }
            files.forEach(file -> {
                try {
                    String fileName = file.getOriginalFilename();
                    String fileType = fileName.substring(fileName.indexOf("."));
                    String filePath = UUID.randomUUID().toString() +fileType;
                    File newFile = new File(dirPath,  filePath);
                    FileCopyUtils.copy(file.getInputStream(),Files.newOutputStream(newFile.toPath()));
                    OaAttachment attachment = new OaAttachment();
                    attachment.setName(fileName);
                    attachment.setType(fileType);
                    attachment.setUrl("oa/uploadFile/"+filePath);
                    attachment.setAttachmentSize(file.getSize());
                    oaAttachmentService.save(attachment);
                    list.add(attachment);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            return R.data(list);
        }
  • 相关阅读:
    2017年5月15号课堂笔记
    2017年5月12号课堂笔记
    2017年5月8号课堂笔记
    2017年5月5号课堂笔记
    2017年4月26号课堂笔记
    不忘初心,坚持走下去
    2017年4月24号课堂笔记
    2017年4月21号课堂笔记
    2017年4月19号课堂笔记
    autoit UIA获取Listview的信息
  • 原文地址:https://www.cnblogs.com/xianz666/p/13523483.html
Copyright © 2011-2022 走看看