download
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import java.io.File;
import java.io.IOException;
@RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> downloadAll() throws IOException {
// 准备好你要下载的文件
File file = GetYourFile();
if(file!= null && file.exists()) {
FileSystemResource resource = new FileSystemResource(file);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", resource.getFilename()));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.length())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(
resource.getInputStream()
));
}
return null;
}
upload
@PostMapping("/uploadFile")
public Boolean uploadHeadImage(
@RequestParam(value = "file") MultipartFile file,
@RequestParam String filename,
@RequestParam String creator
) {
InputStream uploadStream = getStream(file);
if (uploadStream == null) {
return Boolean.false;
}
// 在下面处理文件
/**
* TODO 处理的你文件
*/
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/153502.html