use of uk.nhs.digital.externalstorage.s3.S3Connector in project hippo by NHS-digital-website.
the class S3ConnectorServiceRegistrationModule method doInitialize.
@Override
protected void doInitialize(final Session session) throws RepositoryException {
s3Connector = new S3ConnectorImpl(getAmazonS3(), s3Bucket, new S3ObjectKeyGenerator(this::newRandomString));
HippoServiceRegistry.registerService(s3Connector, S3Connector.class);
}
use of uk.nhs.digital.externalstorage.s3.S3Connector in project hippo by NHS-digital-website.
the class ResourceUploadPlugin method handleUpload.
/**
* Handles the file upload from the form.
*
* @param upload the {@link FileUpload} containing the upload information
*/
private void handleUpload(FileUpload upload) throws FileUploadViolationException {
S3Connector s3Connector = HippoServiceRegistry.getService(S3Connector.class);
String fileName = upload.getClientFileName();
String mimeType = upload.getContentType();
JcrNodeModel nodeModel = (JcrNodeModel) this.getDefaultModel();
Node node = nodeModel.getNode();
try {
S3ObjectMetadata metadata = s3Connector.uploadFile(upload.getInputStream(), fileName, mimeType);
setResourceProperties(node, metadata);
} catch (Exception ex) {
log.error("Cannot upload resource", ex);
throw new FileUploadViolationException(ex.getMessage());
}
}
use of uk.nhs.digital.externalstorage.s3.S3Connector in project hippo by NHS-digital-website.
the class ImageDisplayPlugin method createFileLink.
private ResourceLink createFileLink(S3NodeMetadata metadata) throws RepositoryException {
final S3Connector s3ConnectorService = HippoServiceRegistry.getService(S3Connector.class);
S3FileResourceStream s3FileResourceStream = new S3FileResourceStream(metadata, s3ConnectorService);
ResourceStreamResource resourceStreamResource = new ResourceStreamResource(s3FileResourceStream);
resourceStreamResource.setFileName(metadata.getFileName());
resourceStreamResource.setContentDisposition(ContentDisposition.ATTACHMENT);
ResourceLink filelink = new ResourceLink("link", resourceStreamResource);
filelink.add(new Label("filename", new Model<>(metadata.getFileName())));
return filelink;
}
Aggregations