本文整理汇总了Java中org.springframework.http.HttpHeaders.setContentDispositionFormData方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders.setContentDispositionFormData方法的具体用法?Java HttpHeaders.setContentDispositionFormData怎么用?Java HttpHeaders.setContentDispositionFormData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.HttpHeaders
的用法示例。
在下文中一共展示了HttpHeaders.setContentDispositionFormData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRequestEntity
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
private HttpEntity<MultiValueMap<String, Object>> buildRequestEntity(byte[] packaged,
String notifyToken,
String notifyUrl) {
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
HttpHeaders textHeaders = new HttpHeaders();
textHeaders.setContentType(MediaType.TEXT_PLAIN);
HttpHeaders binaryHeaders = new HttpHeaders();
binaryHeaders.setContentDispositionFormData("file", SUBMISSION_FILENAME);
map.add("file", new HttpEntity<>(new ByteArrayResource(packaged), binaryHeaders));
map.add("token", new HttpEntity<>(notifyToken, textHeaders));
map.add("notify", new HttpEntity<>(notifyUrl, textHeaders));
return new HttpEntity<>(map);
}
示例2: fileDownload
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
/**
* @desc 下载压测数据文件
*
* @author liuliang
*
* @param filename 文件名
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/fileDownload")
public ResponseEntity<byte[]> fileDownload(@RequestParam("filename") String filename,HttpServletRequest request,HttpServletResponse response) {
//1、从ftp下载
byte[] fileContent = ftpUtils.downloadFile(filename);
HttpHeaders headers = new HttpHeaders();
if(null != fileContent){
//2、成功返回
try {
headers.setContentDispositionFormData("attachment", new String(filename.getBytes("UTF-8"),"iso-8859-1"));
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
return new ResponseEntity<byte[]>(fileContent,headers, HttpStatus.CREATED);
} catch (Exception e) {
logger.error("下载压测数据文件异常,filename:{}",filename,e);
}
}
//下载失败返回
logger.warn("从ftp下载压测文件失败,filename:{}",filename);
headers.add("Content-Disposition","attachment;filename=error.log");
return new ResponseEntity<byte[]>(("从FTP服务器下载压测参数文件失败,filename:"+ filename).getBytes(),headers,HttpStatus.OK);
}
示例3: download
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
/**
* 下载
* @param file 文件
* @param fileName 生成的文件名
* @return {ResponseEntity}
*/
protected ResponseEntity<Resource> download(File file, String fileName) {
Resource resource = new FileSystemResource(file);
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
String header = request.getHeader("User-Agent");
// 避免空指针
header = header == null ? "" : header.toUpperCase();
HttpStatus status;
if (header.contains("MSIE") || header.contains("TRIDENT") || header.contains("EDGE")) {
fileName = URLUtils.encodeURL(fileName, Charsets.UTF_8);
status = HttpStatus.OK;
} else {
fileName = new String(fileName.getBytes(Charsets.UTF_8), Charsets.ISO_8859_1);
status = HttpStatus.CREATED;
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<Resource>(resource, headers, status);
}
示例4: genHttpHeaders
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
public HttpHeaders genHttpHeaders(int id, String type, String noteOrNotebook) throws IOException{
String filename = "";
if(noteOrNotebook.equals("note")) {
filename = new String(noteDao.getNoteById(id).getTitle().getBytes("UTF-8"), "iso8859-1") + "." + type;
} else {
filename = new String(notebookDao.getNotebookById(id).getTitle().getBytes("UTF-8"), "iso8859-1") + ".zip";
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", filename);
return headers;
}
示例5: getCoursePage
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
/**
* 获取课表网页
*
* @param userKey 用户认证KEY
* @param forceReresh 是否刷新服务器的缓存
* @return
*/
// @RequestMapping("/coursepage")
// @ResponseBody
// public String getCoursePage(@RequestParam("userkey") String userKey,
// @RequestParam(value = "forcerefresh", required = false) Integer forceReresh) {
// System.out.println("POST /common/coursepage");
//
// boolean reqForceRefresh = forceReresh != null && forceReresh == 1;
//
// String coursePage = null;
// StatusBean statusBean = new StatusBean();
// KeyBean keyBean = keyService.getUserInfo(userKey);
// if (keyBean != null) {
// if (!keyBean.isEvil()) {
// // TODO 风险:可能引起超时
// coursePage = commonService.getCoursePage(keyBean, reqForceRefresh, statusBean);
// } else {
// statusBean.setCode(StatusBean.CODE_ERR_EVIL_USER);
// }
// } else {
// statusBean.setCode(StatusBean.CODE_ERR_USER);
// }
// if (statusBean.getCode() != StatusBean.CODE_SUCCESS) {
// coursePage = statusBean.getCode() + " " + (new StatusVo(statusBean)).getDesc();
// }
//
// return coursePage;
// }
@RequestMapping(value = "/coursepage", method = RequestMethod.POST)
public ResponseEntity<byte[]> getCoursePage(@RequestParam("userkey") String userKey) throws IOException {
System.out.println("POST /common/coursepage");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", "coursepage.zip");
KeyBean keyBean = keyService.getUserInfo(userKey);
if (keyBean != null && !keyBean.isEvil()) {
byte[] bytes = commonService.getCoursePage(keyBean);
return new ResponseEntity<byte[]>(bytes, headers, HttpStatus.CREATED);
}
return null;
}
示例6: file
import org.springframework.http.HttpHeaders; //导入方法依赖的package包/类
/**
* Download attached file.
*/
@GetMapping("/file/{id:[a-f0-9]{64}}/{key:[a-f0-9]{64}}")
public ResponseEntity<StreamingResponseBody> file(@PathVariable("id") final String id,
@PathVariable("key") final String keyHex,
final HttpSession session) {
final KeyIv keyIv =
new KeyIv(BaseEncoding.base16().lowerCase().decode(keyHex), resolveFileIv(id, session));
final DecryptedFile decryptedFile = messageService.resolveStoredFile(id, keyIv);
final HttpHeaders headers = new HttpHeaders();
// Set application/octet-stream instead of the original mime type to force download
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
if (decryptedFile.getName() != null) {
headers.setContentDispositionFormData("attachment", decryptedFile.getName(),
StandardCharsets.UTF_8);
}
headers.setContentLength(decryptedFile.getOriginalFileSize());
final StreamingResponseBody body = out -> {
try (final InputStream in = messageService.getStoredFileInputStream(id, keyIv)) {
ByteStreams.copy(in, out);
out.flush();
}
messageService.burnFile(id);
};
return new ResponseEntity<>(body, headers, HttpStatus.OK);
}