Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class File {

@Column(name = "object_key", nullable = false)
private String objectKey;

@Column(name = "original_filename")
private String originalFilename;

private String fileHash;

@Column(name = "size_bytes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class TempFile {

@Column(name = "object_key", nullable = false)
private String objectKey;

@Column(name = "original_filename")
private String originalFilename;

private String fileHash;

@Column(name = "size_bytes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ public FileProposalResponse uploadFileProposal(UploadFileProposalRequest dto) {

try {
byte[] fileData = dto.getFile().getBytes();
String objectKey = s3StorageService.put(fileData);
String contentType = dto.getFile().getContentType();
String objectKey = contentType != null
? s3StorageService.put(fileData, contentType)
: s3StorageService.put(fileData);
TempFile tempFile = TempFile.builder()
.title(dto.getTitle())
.description(dto.getDescription())
.type(dto.getType())
.objectKey(objectKey)
.originalFilename(dto.getFile().getOriginalFilename())
.fileHash(generateFileHash(fileData)) // Hash seguro
.sizeBytes((long) fileData.length)
.subject(subject)
Expand Down Expand Up @@ -180,8 +184,11 @@ public TempFile downloadFileFromProposal(Long id) {

public FileDownloadResponse getFileDownloadLink(Long id) {
TempFile tempFile = downloadFileFromProposal(id);
String filename = tempFile.getOriginalFilename() != null
? tempFile.getOriginalFilename()
: tempFile.getTitle();
String url = fileUrlSigner.presignedGetUrl(tempFile.getObjectKey(),
ContentDisposition.attachmentOf(tempFile.getTitle()));
ContentDisposition.attachmentOf(filename));
return FileDownloadResponse.builder().url(url).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ public FileDownloadResponse downloadFile(Long id) {
file.incrementDownloadCount();
fileRepository.save(file);

String filename = file.getOriginalFilename() != null
? file.getOriginalFilename()
: file.getTitle();
String url = fileUrlSigner.presignedGetUrl(file.getObjectKey(),
ContentDisposition.attachmentOf(file.getTitle()));
ContentDisposition.attachmentOf(filename));
return FileDownloadResponse.builder().url(url).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ private void applyFileProposal(FileProposal fileProposal) {
.description(tempFile.getDescription())
.type(tempFile.getType())
.objectKey(tempFile.getObjectKey())
.originalFilename(tempFile.getOriginalFilename())
.fileHash(tempFile.getFileHash())
.sizeBytes(tempFile.getSizeBytes())
.uploader(tempFile.getUploader())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- V9: Persistir o nome de arquivo orixinal (con extensión) para descargas
alter table if exists files
add column if not exists original_filename varchar(255);

alter table if exists temp_files
add column if not exists original_filename varchar(255);
Loading