zoukankan      html  css  js  c++  java
  • tfs对接数据-File

    在使用tfs时,数据结构

        /**
         * getFile
         */
        @RequestMapping("/tfs/{fileName}")
        public ResponseEntity<FileSystemResource> getFileImg(HttpServletResponse resp, @PathVariable String fileName){
            MediaType mediaType = MediaType.IMAGE_PNG;
            File file = new File(filePath, fileName + ".png");
            if(!file.exists()){
                file = new File(filePath, defaultName + ".png");
                mediaType = MediaType.IMAGE_JPEG;
            }
            
            
            HttpHeaders header = new HttpHeaders();
            header.add("Cache-Control", "no-cache, no-store, must-revalidate");
            return ResponseEntity.ok().headers(header).contentType(mediaType).body(new FileSystemResource(file));
        }
        
        /**
         * setFile
         * @throws IOException 
         */
        @RequestMapping("/tfs")
        public void setFile(HttpServletRequest request, HttpServletResponse resp) throws IOException{
            InputStream is = request.getInputStream();
            String fileName = "" + System.currentTimeMillis();
            File file = new File(filePath, fileName + ".png");
            OutputStream os = new FileOutputStream(file);
            byte[] byteData = new byte[1024];
            int len = is.read(byteData, 0, 1024);
            while(len > -1){
                os.write(byteData, 0, len);
                len = is.read(byteData, 0, 1024);
            }
             os.flush();
             os.close();
             is.close();
             
            String respStr = "{"TFS_FILE_NAME":"" + fileName + ""}";
            resp.setContentType("binary/octet-stream");
            resp.setCharacterEncoding("utf-8");
            resp.getWriter().write(respStr);
        }
  • 相关阅读:
    tableView
    ios设计模式 设计一个应用程序 笔记
    Touching the Background to close the Keyboard
    fdfd
    fdffafadf
    Declaring the Action Method
    网易公开课IOS笔记 第二课
    getters and setters
    objective c
    Google编码规范 C++ Style Guide, JavaScript Style Guide, ObjectiveC Style Guide, and Python Style Guide
  • 原文地址:https://www.cnblogs.com/DennyZhao/p/9470014.html
Copyright © 2011-2022 走看看