@Override public F.Promise<Result> getDownload(String key, String name) { GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key); ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides(); responseHeaders.setContentDisposition("attachment; filename=" + name); generatePresignedUrlRequest.setResponseHeaders(responseHeaders); AmazonS3 amazonS3 = new AmazonS3Client(credentials); try { URL url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest); return F.Promise.pure(redirect(url.toString())); } catch (AmazonClientException ace) { Logger.error( "Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network." + " Error Message: " + ace.getMessage()); return F.Promise.pure(internalServerError("Download failed")); } }
/** * Sets the content disposition response header override. * * @return This {@link ResponseHeaderOverrides} object for method chaining. * @see ResponseHeaderOverrides#RESPONSE_HEADER_CONTENT_DISPOSITION */ public ResponseHeaderOverrides withContentDisposition(String contentDisposition) { setContentDisposition(contentDisposition); return this; }