Skip to content

Commit

Permalink
feat: adds resulting file url to response
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbranham committed Aug 19, 2024
1 parent 6e114c8 commit aef72e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import net.savantly.nexus.flow.dom.files.FileEntities;
Expand Down Expand Up @@ -86,12 +87,17 @@ public ResponseEntity submitFormJson(@PathVariable String formId, @RequestBody M
}

@PostMapping(value = "/files/{organizationId}")
public ResponseEntity createFile(@RequestParam("file") MultipartFile file, @PathVariable String organizationId) {
public ResponseEntity createFile(@RequestParam("file") MultipartFile file, @PathVariable String organizationId,
HttpServletRequest request) {
log.info("Requested to upload file");
try {
var entity = files.uploadFile(organizationId, file);
log.info("File uploaded: {}", entity);
var dto = new FileEntityDto().setId(entity.getId());

// 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);
return ResponseEntity.ok(dto);
} catch (IOException e) {
log.error("Failed to upload file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@Accessors(chain = true)
public class FileEntityDto {
private String id;
private String url;
}

0 comments on commit aef72e0

Please sign in to comment.