mirror of
https://github.com/RoastSlav/quickdrop.git
synced 2026-01-05 05:59:59 -06:00
added content_length to the response when downloading and added url encoding to the filename
This commit is contained in:
@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDate;
|
||||
@@ -143,7 +145,9 @@ public class FileService {
|
||||
try {
|
||||
Resource resource = new UrlResource(outputFile.toUri());
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileEntity.name + "\"")
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + URLEncoder.encode(fileEntity.name, StandardCharsets.UTF_8) + "\"")
|
||||
.header(HttpHeaders.CONTENT_TYPE, "application/octet-stream")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, String.valueOf(resource.contentLength()))
|
||||
.body(resource);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error reading file: {}", e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user