List of usage examples for org.springframework.http HttpHeaders setContentDispositionFormData
public void setContentDispositionFormData(String name, @Nullable String filename)
From source file:com.courtalon.gigaMvcGalerie.web.ImageController.java
@RequestMapping(value = "/images/thumbdata/{id:[0-9]+}", method = RequestMethod.GET) @ResponseBody/* w ww .jav a2s.c om*/ public ResponseEntity<FileSystemResource> downloadThumbImage(@PathVariable("id") int id) { Image img = imageRepository.findOne(id); HttpHeaders respHeaders = new HttpHeaders(); respHeaders.setContentType(MediaType.parseMediaType("image/jpeg")); respHeaders.setContentDispositionFormData("attachment", "thumb_" + id + ".jpeg"); Optional<File> f = getImageRepository().getImageThumbFile(img.getId()); if (f.isPresent()) { log.info("fichier pour thumbnail image no " + id + " trouv"); FileSystemResource fsr = new FileSystemResource(f.get()); return new ResponseEntity<FileSystemResource>(fsr, respHeaders, HttpStatus.OK); } else { log.info("fichier pour thumbnail image no " + id + " introuvable"); return new ResponseEntity<FileSystemResource>(HttpStatus.NOT_FOUND); } }
From source file:com.courtalon.gigaMvcGalerie.web.ImageController.java
@RequestMapping(value = "/images/data/{id:[0-9]+}", method = RequestMethod.GET) @ResponseBody/* w w w.java 2s .c o m*/ public ResponseEntity<FileSystemResource> downloadImage(@PathVariable("id") int id) { Image img = imageRepository.findOne(id); if (img == null) throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "image not found"); HttpHeaders respHeaders = new HttpHeaders(); respHeaders.setContentType(MediaType.parseMediaType(img.getContentType())); respHeaders.setContentLength(img.getFileSize()); respHeaders.setContentDispositionFormData("attachment", img.getFileName()); Optional<File> f = getImageRepository().getImageFile(img.getId()); if (f.isPresent()) { log.info("fichier pour image no " + id + " trouv"); FileSystemResource fsr = new FileSystemResource(f.get()); return new ResponseEntity<FileSystemResource>(fsr, respHeaders, HttpStatus.OK); } else { log.info("fichier pour image no " + id + " introuvable"); throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "image file not found"); } }
From source file:org.shaf.server.controller.CmdActionController.java
/** * Gets data from the server.//w w w. j a va 2 s .com * * @param storage * the resource type. * @param alias * the data alias. * @return the entity for downloading data. * @throws Exception * if an error occurs. */ @RequestMapping(value = "/download/{storage}/{alias}", method = RequestMethod.GET) public @ResponseBody ResponseEntity<InputStreamResource> onDownload(@PathVariable String storage, @PathVariable String alias) throws Exception { LOG.debug("CALL service: /cmd/download/{" + storage + "}/{" + alias + "}"); Firewall firewall = super.getFirewall(); String username = super.getUserName(); StorageDriver driver = OPER.getStorageDriver(firewall, username, StorageType.CONSUMER, storage); HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.APPLICATION_OCTET_STREAM); header.setContentLength(driver.getLength(alias)); header.setContentDispositionFormData("attachment", alias); return new ResponseEntity<InputStreamResource>(new InputStreamResource(driver.getInputStream(alias)), header, HttpStatus.OK); }
From source file:eu.supersede.gr.rest.GameRest.java
@RequestMapping("/{gameId}/exportGameResults") public ResponseEntity<?> exportGameResults(@PathVariable Long gameId) { HAHPGame g = games.findOne(gameId);/* w w w .j a va2 s. c o m*/ if (g == null) { throw new NotFoundException(); } StringBuilder result = new StringBuilder(); result.append("REQUIREMENT").append(SEPARATOR).append("RESULT").append(NEW_LINE); List<HAHPCriteriasMatrixData> criteriasMatrixDataList = criteriasMatricesData.findByGame(g); Map<String, Double> rs = AHPRest.CalculateAHP(g.getCriterias(), g.getRequirements(), criteriasMatrixDataList, g.getRequirementsMatrixData()); for (Entry<String, Double> e : rs.entrySet()) { result.append(requirements.getOne(new Long(e.getKey())).getName()).append(SEPARATOR) .append(e.getValue()).append(NEW_LINE); } HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(new MediaType("text", "csv", Charset.forName("utf-8"))); httpHeaders.setContentDispositionFormData("attachment", "dmp_" + g.getGameId() + "_results.csv"); return new ResponseEntity<>(result.toString(), httpHeaders, HttpStatus.OK); }
From source file:eu.supersede.gr.rest.GameRest.java
@RequestMapping("/{gameId}/exportGameData") public ResponseEntity<?> exportGameData(@PathVariable Long gameId) { HAHPGame g = games.findOne(gameId);/*from ww w.j av a 2 s . c o m*/ if (g == null) { throw new NotFoundException(); } StringBuilder result = new StringBuilder(); result.append("REQUIREMENT1").append(SEPARATOR).append("REQUIREMENT2").append(SEPARATOR).append("CRITERIA") .append(SEPARATOR).append("USER").append(SEPARATOR).append("VOTE").append(SEPARATOR) .append("VOTE_TIME").append(NEW_LINE); for (HAHPRequirementsMatrixData rmd : g.getRequirementsMatrixData()) { for (HAHPPlayerMove pm : rmd.getPlayerMoves()) { if (pm.getPlayed()) { result.append(rmd.getRowRequirement().getName()).append(SEPARATOR) .append(rmd.getColumnRequirement().getName()).append(SEPARATOR) .append(rmd.getCriteria().getName()).append(SEPARATOR).append(pm.getPlayer().getName()) .append(SEPARATOR).append(pm.getValue()).append(SEPARATOR); if (pm.getPlayedTime() == null) { result.append(ZERO_TIME); } else { result.append(dateFormat.format(pm.getPlayedTime())); } result.append(NEW_LINE); } } } HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(new MediaType("text", "csv", Charset.forName("utf-8"))); httpHeaders.setContentDispositionFormData("attachment", "dmp_" + g.getGameId() + "_data.csv"); return new ResponseEntity<>(result.toString(), httpHeaders, HttpStatus.OK); }
From source file:net.paslavsky.springrest.HttpHeadersHelper.java
private void setContentDisposition(HttpHeaders headers, String headerName, Object headerValue) { String name;// w w w . j ava2s . c o m String filename = null; if (headerValue instanceof String) { name = (String) headerValue; } else if (headerValue instanceof String[]) { name = ((String[]) headerValue)[0]; filename = ((String[]) headerValue)[1]; } else { throw new SpringRestClientException( String.format("Can't cast %s to the java.lang.String[]", headerValue.getClass().getName())); } if (name.toLowerCase().startsWith("form-data;")) { headers.set(headerName, name); } else { headers.setContentDispositionFormData(name, filename); } }
From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java
@RequestMapping("teacher/download") public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response) throws IOException { String term = request.getParameter("term"); String courseName = request.getParameter("courseName"); String workid = request.getParameter("workid"); String sn = getCurrentUsername(); String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege(); String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName(); String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/" + courseName + "/" + workid + "/"; // String fileNamelast = workid + ".zip";//?? file(getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/" + ""); String compress = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/" + "" + "/" + fileNamelast; //?/* www . j a v a 2 s . c o m*/ ZipCompressor zc = new ZipCompressor(compress);//? zc.compress(path, "", ""); //??? //? File file = new File(compress); HttpHeaders headers = new HttpHeaders(); String fileName = new String(fileNamelast.getBytes("UTF-8"), "iso-8859-1");//??? headers.setContentDispositionFormData("attachment", fileName); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }
From source file:cn.edu.henu.rjxy.lms.controller.TeaController.java
@RequestMapping("teacher/downloadclas") public ResponseEntity<byte[]> downloadclass(HttpServletRequest request, HttpServletResponse response) throws IOException { String term = request.getParameter("term"); String courseName = request.getParameter("courseName"); String workid = request.getParameter("workid"); String classname = request.getParameter("classname"); String sn = getCurrentUsername(); String collage = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherCollege(); String teacherName = TeacherDao.getTeacherBySn(getCurrentUsername()).getTeacherName(); String path = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/" + courseName + "/" + workid + "/" + classname + "/"; // String fileNamelast = classname + ".zip";//?? file(getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/" + ""); String compress = getFileFolder(request) + "uploadhomework/" + term + "/" + collage + "/" + sn + "/" + teacherName + "/" + "" + "/" + fileNamelast; //?/* ww w.j a v a2 s . c o m*/ ZipCompressor zc = new ZipCompressor(compress);//? zc.compress(path, "", ""); //??? //? File file = new File(compress); HttpHeaders headers = new HttpHeaders(); String fileName = new String(fileNamelast.getBytes("UTF-8"), "iso-8859-1");//??? headers.setContentDispositionFormData("attachment", fileName); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }
From source file:com.oriental.manage.controller.merchant.settleManage.MerchantContranctController.java
@RequestMapping("/downEnclosure") @RequiresPermissions("org-contaract_down") public ResponseEntity<byte[]> downEnclosure(String id) { try {/*from ww w. ja v a 2s . c o m*/ ContractInfo contractInfo = contractService.queryById(id); String path = downloadTempDir.concat("/").concat(contractInfo.getCompanyCode()).concat("/"); FileUtilsExt.writeFile(path); String[] pathList = { contractInfo.getDfsBankFile(), contractInfo.getDfsBizLicenseCert(), contractInfo.getDfsContAttach(), contractInfo.getDfsOpenBankCert(), contractInfo.getDfsOrganizationCodeCert(), contractInfo.getDfsRatePayerCert(), contractInfo.getDfsTaxRegisterCert() }; for (String dfsPath : pathList) { if (StringUtils.isNotBlank(dfsPath)) { DfsFileInfo dfsFileInfo = new DfsFileInfo(); dfsFileInfo.setDfsFullFilename(dfsPath); List<DfsFileInfo> fileInfoList = iDfsFileInfoService.searchDfsFileInfo(dfsFileInfo); if (null != fileInfoList && fileInfoList.size() > 0) { DfsFileInfo dfsFileInfo1 = fileInfoList.get(0); fastDFSPoolUtil.download(dfsFileInfo1.getDfsGroupname(), dfsFileInfo1.getDfsFullFilename(), path.concat(dfsFileInfo1.getLocalFilename())); } } } String localFileName = downloadTempDir.concat("/").concat(contractInfo.getCompanyCode()) .concat("???.zip"); FileUtilsExt.zipFile(Arrays.asList(new File(path).listFiles()), localFileName); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentDispositionFormData("attachment", new String( contractInfo.getCompanyCode().concat("???.zip").getBytes("UTF-8"), "ISO-8859-1")); return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(new File(localFileName)), headers, HttpStatus.CREATED); } catch (Exception e) { log.error("", e); } return null; }
From source file:com.teasoft.teavote.controller.BackupController.java
@RequestMapping(value = "/api/teavote/back-up", method = RequestMethod.GET) @ResponseBody//from w w w .j a v a 2s. c o m public HttpEntity<byte[]> backup(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpHeaders httpHeaders = new HttpHeaders(); String dbName = env.getProperty("teavote.db"); String dbUserName = env.getProperty("teavote.user"); String dbPassword = utilities.getPassword(); DateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss"); Date dateobj = new Date(); String fileName = "teavote_backup_" + df.format(dateobj) + ".sql"; String path = new ConfigLocation().getConfigPath() + File.separator + fileName; if (!utilities.backupDB(dbName, dbUserName, dbPassword, path)) { return null; } //Sign file sig.signData(path); File backupFile = new File(path); byte[] bytes; try (InputStream backupInputStream = new FileInputStream(backupFile)) { httpHeaders.setContentType(MediaType.TEXT_PLAIN); httpHeaders.setContentDispositionFormData("Backup", fileName); bytes = IOUtils.toByteArray(backupInputStream); backupInputStream.close(); } backupFile.delete(); return new ResponseEntity<>(bytes, httpHeaders, HttpStatus.OK); }