本文整理匯總了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);
}