Skip to content

Commit

Permalink
add api key to download url
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbranham committed Aug 20, 2024
1 parent 3d02f13 commit 1a44eb6
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,20 @@ public ResponseEntity submitFormJson(@PathVariable String formId, @RequestBody M

@PostMapping(value = "/files/{organizationId}")
public ResponseEntity createFile(@RequestParam("file") MultipartFile file, @PathVariable String organizationId,
@RequestParam(name = "public", required = false) Boolean isPublic,
HttpServletRequest request) {
log.info("Requested to upload file");
try {
var entity = files.uploadFile(organizationId, file);
if (Objects.nonNull(isPublic)) {
entity.setPublicFile(isPublic);
}
log.info("File uploaded: {}", entity);

// get the url used to download the file
var url = request.getRequestURL().toString().replace(organizationId, entity.getId());

var dto = new FileEntityDto().setId(entity.getId()).setUrl(url);
var urlWithApiKey = url + "?api-key=" + entity.getApiKey();
var dto = new FileEntityDto().setId(entity.getId()).setUrl(urlWithApiKey);
return ResponseEntity.ok(dto);
} catch (IOException e) {
log.error("Failed to upload file", e);
Expand All @@ -107,7 +111,7 @@ public ResponseEntity createFile(@RequestParam("file") MultipartFile file, @Path

@GetMapping("/files/{fileId}")
public ResponseEntity downloadFile(@PathVariable String fileId,
@RequestParam(name = "key", required = false) String apiKey) {
@RequestParam(name = "api-key", required = false) String apiKey) {
log.info("Requested to get file: {}", fileId);
var entity = files.findById(fileId);
if (entity.isEmpty()) {
Expand Down

0 comments on commit 1a44eb6

Please sign in to comment.