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());
}
}
Aggregations