Updated upload endpoint to use java map
This commit is contained in:
parent
36d085bfbc
commit
f86b4f66d0
@ -14,6 +14,9 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
public class Upload extends ApiRestController {
|
public class Upload extends ApiRestController {
|
||||||
@ -27,7 +30,7 @@ public class Upload extends ApiRestController {
|
|||||||
|
|
||||||
// Currently testing
|
// Currently testing
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public ResponseEntity<String> getUpload(@RequestParam("file") MultipartFile file, HttpServletRequest request,
|
public ResponseEntity<Map<String, Object>> getUpload(@RequestParam("file") MultipartFile file, HttpServletRequest request,
|
||||||
@RequestParam(value = "passwordProtected", required = false) Boolean passwordProtected,
|
@RequestParam(value = "passwordProtected", required = false) Boolean passwordProtected,
|
||||||
@RequestParam(value = "singleDownload", defaultValue = "false") boolean singleDownload,
|
@RequestParam(value = "singleDownload", defaultValue = "false") boolean singleDownload,
|
||||||
@RequestParam(value = "fileDescription", required = false) String fileDescription) {
|
@RequestParam(value = "fileDescription", required = false) String fileDescription) {
|
||||||
@ -36,21 +39,23 @@ public class Upload extends ApiRestController {
|
|||||||
|
|
||||||
if (file.isEmpty()) {
|
if (file.isEmpty()) {
|
||||||
log.debug("User tried to upload an empty file. IP: " + request.getRemoteAddr());
|
log.debug("User tried to upload an empty file. IP: " + request.getRemoteAddr());
|
||||||
return new ResponseEntity<>("Please select a file to upload.", HttpStatus.NOT_ACCEPTABLE);
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("message", "Please select a file to upload.");
|
||||||
|
return new ResponseEntity<>(response, HttpStatus.NOT_ACCEPTABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileUpload fileUpload = fileService.processUploadedFile(file, request.getRemoteAddr(), passwordProtected, singleDownload, fileDescription);
|
FileUpload fileUpload = fileService.processUploadedFile(file, request.getRemoteAddr(), passwordProtected, singleDownload, fileDescription);
|
||||||
log.debug("User uploaded file " + file.getOriginalFilename() + " from IP " + request.getRemoteAddr() + " successfully.");
|
log.debug("User uploaded file " + file.getOriginalFilename() + " from IP " + request.getRemoteAddr() + " successfully.");
|
||||||
|
|
||||||
JsonObject response = new JsonObject();
|
Map<String, Object> response = new HashMap<>();
|
||||||
response.addProperty("fileId", fileUpload.getFileId());
|
response.put("fileId", fileUpload.getFileId());
|
||||||
response.addProperty("fileName", fileUpload.getFileName());
|
response.put("fileName", fileUpload.getFileName());
|
||||||
response.addProperty("message", "File " + file.getOriginalFilename() + " uploaded successfully!");
|
response.put("message", "File " + fileUpload.getFileName() + " uploaded successfully!");
|
||||||
response.addProperty("passwordProtected", fileUpload.isPasswordProtected());
|
response.put("passwordProtected", fileUpload.isPasswordProtected());
|
||||||
response.addProperty("singleDownload", fileUpload.isSingleDownload());
|
response.put("singleDownload", fileUpload.isSingleDownload());
|
||||||
response.addProperty("uploadDate", fileUpload.getUploadDate().toString());
|
response.put("uploadDate", fileUpload.getUploadDate().toString());
|
||||||
response.addProperty("password", fileUpload.getDownloadPassword());
|
response.put("password", fileUpload.getDownloadPassword());
|
||||||
|
|
||||||
return new ResponseEntity<>(response.toString(), HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user