|
|
|
@ -7,11 +7,15 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import ru.ulstu.configuration.Constants;
|
|
|
|
|
import ru.ulstu.core.model.response.Response;
|
|
|
|
|
import ru.ulstu.file.model.File;
|
|
|
|
|
import ru.ulstu.file.model.FileData;
|
|
|
|
|
import ru.ulstu.file.service.FileService;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
|
import static ru.ulstu.paper.controller.PaperController.URL;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@ -28,17 +32,18 @@ public class FileController {
|
|
|
|
|
@GetMapping("/download-tmp/{tmp-file-name}")
|
|
|
|
|
public ResponseEntity<byte[]> getFile(@PathVariable("tmp-file-name") String tmpFileName) throws IOException {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
headers.add("Content-Disposition", "attachment; filename="
|
|
|
|
|
+ fileService.getTmpFileName(tmpFileName));
|
|
|
|
|
headers.add("Content-Disposition", "attachment; filename='"
|
|
|
|
|
+ URLEncoder.encode(fileService.getTmpFileName(tmpFileName), UTF_8.toString()) + "'");
|
|
|
|
|
return new ResponseEntity<>(fileService.getTmpFile(tmpFileName), headers, HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/download/{file-id}")
|
|
|
|
|
public ResponseEntity<byte[]> getFile(@PathVariable("file-id") Integer fileId) {
|
|
|
|
|
public ResponseEntity<byte[]> getFile(@PathVariable("file-id") Integer fileId) throws UnsupportedEncodingException {
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
File file = fileService.getFile(fileId);
|
|
|
|
|
headers.add("Content-Disposition", "attachment; filename=" + file.getName());
|
|
|
|
|
return new ResponseEntity<>(file.getData(), headers, HttpStatus.OK);
|
|
|
|
|
FileData fileData = fileService.getFile(fileId);
|
|
|
|
|
headers.add("Content-Disposition", "attachment; filename='" +
|
|
|
|
|
URLEncoder.encode(fileData.getName(), UTF_8.toString()) + "'");
|
|
|
|
|
return new ResponseEntity<>(fileData.getData(), headers, HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/uploadTmpFile")
|
|
|
|
|