Search in sources :

Example 1 with FileUploadViolationException

use of org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException 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 {
    final PooledS3Connector s3Connector = HippoServiceRegistry.getService(PooledS3Connector.class);
    String fileName = upload.getClientFileName();
    String mimeType = upload.getContentType();
    try {
        final S3ObjectMetadata s3ObjectMetadata = s3Connector.upload(wrapCheckedException(upload::getInputStream), fileName, mimeType);
        JcrNodeModel nodeModel = (JcrNodeModel) this.getDefaultModel();
        Node node = nodeModel.getNode();
        try {
            setResourceProperties(node, s3ObjectMetadata);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    } catch (Exception ex) {
        log.error("Cannot upload resource", ex);
        throw new FileUploadViolationException(ex.getMessage());
    }
}
Also used : PooledS3Connector(uk.nhs.digital.externalstorage.s3.PooledS3Connector) FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) Node(javax.jcr.Node) S3ObjectMetadata(uk.nhs.digital.externalstorage.s3.S3ObjectMetadata) JcrNodeModel(org.hippoecm.frontend.model.JcrNodeModel) FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) RepositoryException(javax.jcr.RepositoryException) PooledS3Connector.wrapCheckedException(uk.nhs.digital.externalstorage.s3.PooledS3Connector.wrapCheckedException)

Aggregations

Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 JcrNodeModel (org.hippoecm.frontend.model.JcrNodeModel)1 FileUploadViolationException (org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException)1 PooledS3Connector (uk.nhs.digital.externalstorage.s3.PooledS3Connector)1 PooledS3Connector.wrapCheckedException (uk.nhs.digital.externalstorage.s3.PooledS3Connector.wrapCheckedException)1 S3ObjectMetadata (uk.nhs.digital.externalstorage.s3.S3ObjectMetadata)1