0

Is it possible to use inputStreamResource to respond in a fractional way to just one request?

The client would make just one request to the endpoint and the server would send the split file until it was sent in full.

private val PIECE_SIZE = 2048?



 @RestController
@RequestMapping("/download")
class PdfController {
    private val amazonS3: AmazonS3

    init {
        val credentials = BasicAWSCredentials("mycredential", "myCredential2")

        amazonS3 = AmazonS3ClientBuilder.standard()
            .withCredentials(AWSStaticCredentialsProvider(credentials))
            .withRegion(Regions.US_EAST_1)
            .build()
    }

    @GetMapping(value = ["/download/pdf"], produces = [MediaType.APPLICATION_PDF_VALUE])
    fun downloadPdf(): ResponseEntity<Resource> {
        val bucketName = "bucket-name"
        val key = "file.pdf"     
        val s3Object = amazonS3.getObject(GetObjectRequest(bucketName, key))
        val s3InputStream: S3ObjectInputStream = s3Object.objectContent

        val responseHeaders = HttpHeaders()
        responseHeaders.contentType = MediaType.APPLICATION_PDF
        responseHeaders.set("Content-Disposition", "attachment; filename=file.pdf")

        val inputStreamResource = InputStreamResource(s3InputStream)

        return ResponseEntity(inputStreamResource, responseHeaders, HttpStatus.OK)
    }
}
Manzini
  • 1,671
  • 2
  • 9
  • 15

0 Answers0