Search in sources :

Example 1 with JcrNodeModel

use of org.hippoecm.frontend.model.JcrNodeModel 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());
    }
}
Also used : 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) S3Connector(uk.nhs.digital.externalstorage.s3.S3Connector) FileUploadViolationException(org.hippoecm.frontend.plugins.jquery.upload.FileUploadViolationException) RepositoryException(javax.jcr.RepositoryException)

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 S3Connector (uk.nhs.digital.externalstorage.s3.S3Connector)1 S3ObjectMetadata (uk.nhs.digital.externalstorage.s3.S3ObjectMetadata)1