Attachment Validation Application

Last modified by Admin on 2024/03/18 01:55

cogUser Interface for the attachments validation
TypeXAR
CategoryApplication
Developed by

XWiki Development Team

Active Installs0
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Compatibility

14.10RC1+

Installable with the Extension Manager

Description

The Attachment Validation Application provides the UI and Configuration of the attachment validation extension.
This extension also provides the client-side validations for the size and mime type attachment validations.

Related pages:

Administration

The mimetype allowed/blocked on a space can be configured.

xwiki.properties

  
xwiki.properties allow to configure the default mimetype restrictions at farm level.

#-# [Since 14.10RC1]
#-# Define the list of allowed attachment mimetypes. By default, this list is empty, but you can specify a 
#-# comma-separated list of allowed mimetypes. Note that a joker (*) can be used to accept any media type. Once this
#-# list is not empty, any attachment with an unlisted mimetype will be rejected.
#-# For instance, if you want to only accept plain text and any kind of images, you can set the list to:
#-# text/plain,image/*
# attachment.upload.allowList=

#-# [Since 14.10RC1]
#-# Define the list of blocked attachment mimetypes. By default, this list is empty, but you can specify a 
#-# comma-separated list of blocked mimetypes. Note that a joker (*) can be used to accept any media type. Once this 
#-# list is not empty, any attachment matching one of the listed mimetype will be rejected.
#-# For instance, if you want to reject plain text and any kind of images, you can set the list to:
#-# text/plain,image/*
#-#
# attachment.upload.blockList=

Administration UI

attachment_restriction_admin.png

The mimetype restrictions can also be configured at wiki or space level through the administration UI, by visiting the Attachments Restriction section of the administration.

Javascript

An new event is triggered when an attachment is uploaded: xwiki:actions:beforeUpload. An object with a single file key is passed along the event, giving access to the file that must be validated.
A listener can mark the attachment as invalid by calling event.preventDefault().

The example below is a validator that always block the upload of any attachment, and display an error message after each upload.

$(document).on('xwiki:actions:beforeUpload', function (event, data) {
 new XWiki.widgets.Notification("Upload nothing", "error");
  event.preventDefault();
})

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Dependencies

Dependencies for this extension (org.xwiki.platform:xwiki-platform-attachment-validation-ui 16.1.0):

  • org.xwiki.platform:xwiki-platform-attachment-validation-default 16.1.0
Tags:
    

Get Connected