Attachment Validation Application

Last modified by Manuel Leduc on 2022/11/22 11:11

cogAllow to define attachment restrictions and to validate them on attachment upload.
TypeXAR
Category
Developed byUnknown
Rating
0 Votes
LicenseUnknown
Bundled With

XWiki Standard

Compatibility

14.10RC1+

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

Get Connected