This commit is contained in:
Francesco
2023-09-20 20:18:56 +02:00
parent d34676f7a7
commit 82311fd23e
8 changed files with 51 additions and 25 deletions

View File

@@ -22,6 +22,7 @@ import tech.ailef.dbadmin.dbmapping.DbAdminRepository;
import tech.ailef.dbadmin.dbmapping.DbFieldValue;
import tech.ailef.dbadmin.dbmapping.DbObject;
import tech.ailef.dbadmin.dbmapping.DbObjectSchema;
import tech.ailef.dbadmin.exceptions.DbAdminException;
@Controller
@RequestMapping("/dbadmin/download")
@@ -65,7 +66,18 @@ public class DownloadController {
if (object.isPresent()) {
DbObject dbObject = object.get();
DbFieldValue dbFieldValue = dbObject.get(fieldName);
DbFieldValue dbFieldValue;
try {
dbFieldValue = dbObject.get(fieldName);
} catch (DbAdminException e) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Field not found", e);
}
if (dbFieldValue.getValue() == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "There's no file attached to this item");
}
byte[] file = (byte[])dbFieldValue.getValue();
String filename = schema.getClassName() + "_" + id + "_" + fieldName;