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;
}
}