diff --git a/avni-server-api/src/main/java/org/avni/server/web/MediaController.java b/avni-server-api/src/main/java/org/avni/server/web/MediaController.java index 2a30c34b7..7b2463e62 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/MediaController.java +++ b/avni-server-api/src/main/java/org/avni/server/web/MediaController.java @@ -13,6 +13,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -25,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import java.awt.*; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URL; @@ -179,4 +182,14 @@ private boolean isInvalidDimension(File tempSourceFile, AvniFiles.ImageType imag Dimension dimension = AvniFiles.getImageDimension(tempSourceFile, imageType); return dimension.getHeight() > 75 || dimension.getWidth() > 75; } + + @GetMapping("/web/media/downloadStream") + public ResponseEntity downloadFile(@RequestParam String s3Url, @RequestParam String fileName) throws IOException { + InputStreamResource resource = new InputStreamResource(s3Service.getObjectContentFromUrl(s3Url)); + + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName) + .contentType(MediaType.parseMediaType("application/octet-stream")) + .body(resource); + } }