Wiki source code of Attachments

Version 30.1 by Thomas Mortagne on 2017/11/13

Hide last authors
AdrianFita 8.1 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
Caleb James DeLisle 5.1 4
Vincent Massol 13.4 5 Attachments can be uploaded either through the regular [[upload action>>platform:Features.Attachments]], [[platform:Features.WebDAV]], [[XML-RPC>>extensions:Extension.XML-RPC Integration]] or [[Rest>>platform:Features.XWikiRESTfulAPI]].
Caleb James DeLisle 1.1 6 As an administrator you can set limits on the maximum size of an attachment and where the attachments will be stored.
7
8 = Size Limit =
AdrianFita 8.1 9
Manuel Smeria 10.2 10 The maximum size of an attachment is limited by a configuration parameter in the //XWikiPreferences// document. It is set to about 32MB by default.
11 To change it follow these steps:
AdrianFita 8.1 12
Manuel Smeria 10.2 13 1. Go to //{{{http://<yourwiki>/xwiki/bin/edit/XWiki/XWikiPreferences?editor=object}}}//
14 1. Click on the line that says ##XWikiPreferences 0## (right below the line that says ##Objects of type XWiki.XWikiPreferences (1)##)
15 1. Scroll down to the field that says ##Maximum Upload Size## and change the number to whatever size you want (it is expressed in bytes)
16 1. Scroll to the bottom and click "Save"
Caleb James DeLisle 1.1 17
Anca Luca 22.1 18 {{warning}}
Manuel Smeria 24.1 19 Note that if you've already tried to attach a file and it failed, in order for the new size setting to be taken into account you might need to clear your browser's cache.
Anca Luca 23.1 20 {{/warning}}
Anca Luca 22.1 21
Caleb James DeLisle 3.1 22 = Versions =
AdrianFita 8.1 23
Manuel Smeria 10.2 24 When a user uploads an attachment and then uploads another attachment with the exact same name, you can decide whether or not to keep a version history of the attachments like you do with documents.
Ecaterina Moraru (Valica) 27.3 25 XWiki stores all document attachment versions by default which costs more storage space. If you need only latest versions of attachments, you can disable attachment version control by editing your [[xwiki.cfg>>Documentation.AdminGuide.Configuration#HSamplexwiki.cfg]] and adding:
Caleb James DeLisle 3.1 26
AdrianFita 8.1 27 {{code language="none"}}
28 xwiki.store.attachment.versioning=0
29 {{/code}}
Caleb James DeLisle 3.1 30
31 = Deletion =
AdrianFita 8.1 32
Ecaterina Moraru (Valica) 27.3 33 Deleted attachments are stored in a recycle bin so that they can be restored along with the document when rolling back or previewing an earlier version where the attachment should be visible. To disable this feature, edit [[xwiki.cfg>>Documentation.AdminGuide.Configuration#HSamplexwiki.cfg]] and add:
Caleb James DeLisle 3.1 34
AdrianFita 8.1 35 {{code language="none"}}
36 storage.attachment.recyclebin=0
37 {{/code}}
Caleb James DeLisle 3.1 38
Caleb James DeLisle 4.1 39 You can view the list of deleted attachments in your wiki and delete them permanently by going to ##XWiki.DeletedAttachments## in your wiki.
Caleb James DeLisle 3.1 40
Caleb James DeLisle 1.1 41 = Attachment Storage =
AdrianFita 8.1 42
Caleb James DeLisle 1.1 43 XWiki offers plugin attachment storage mechanisms so you can store your attachments in the database or directly in the filesystem.
44
45 No matter what type of attachment store you use, the meta-data for the attachment will be saved in the [[xwikiattachment>>platform:DevGuide.DsXWikiAttachment]] table for faster loads.
46
47 == Database Attachment Store (Default) ==
AdrianFita 8.1 48
Manuel Smeria 10.2 49 This attachment storage mechanism stores your attachments in database entries in the [[xwikiattachment_content>>platform:DevGuide.DsXWikiAttachmentContent]], [[xwikiattachment_archive>>platform:DevGuide.XWikiAttachmentArchive]] and [[xwikiattrecyclebin>>platform:DevGuide.DsXwikiRecycleBin]] tables. This system allows for easy backup of your attachments by dumping the database and keeping all of your data together, but attachment size is memory constrained since the attachment content and archive must all be held in memory. As a general rule, attachments larger than 30MB are not possible.
Caleb James DeLisle 1.1 50
Manuel Smeria 10.2 51 {{info}}
Ecaterina Moraru (Valica) 27.3 52 When using this attachment store with a MySQL database, you must set the ##max_allowed_packet## to about 3 times the size of your largest attachment since the attachment and its version history must be saved. See the [[MySQL Installation guide>>Documentation.AdminGuide.InstallationMySQL]] for more information.
Manuel Smeria 10.2 53 {{/info}}
54
Vincent Massol 11.1 55 == Filesystem Attachment Store ==
Caleb James DeLisle 1.1 56
Manuel Smeria 10.2 57 The Filesystem attachment store saves your attachments in files in a directory tree. This means you will have one more thing to do when you back up your data but it also means you can save larger (over one gigabyte) files. Filesystem attachment store implements a two stage commit mechanism to maintain integrity even if the database fails to commit the attachment meta-data.
Giovanni Júnior 10.1 58
Dmitry Bakbardin 12.1 59 {{error}}
Vincent Massol 29.1 60 The following limitations currently exist when using the filesystem for storing attachments:
61
62 * You must be on a case-sensitive Filesystem. For example if you're on Windows then you might have issue if you create pages with the same name but different case (e.g. ##abc## vs ##Abc##). XWiki is case-sensitive and will end up overwriting attachments if you have several pages with the same name (but different case).
Dmitry Bakbardin 12.1 63 {{/error}}
64
Vincent Massol 18.1 65 === Enabling Filesystem attachment store ===
Dmitry Bakbardin 12.1 66
Vincent Massol 18.1 67 ==== New users ====
68
Ecaterina Moraru (Valica) 27.3 69 If you are a new XWiki user, all you need to do for enabling Filesystem Attachment Store is to change some settings in the [[xwiki.cfg>>Documentation.AdminGuide.Configuration#HSamplexwiki.cfg]] file.
Vincent Massol 18.1 70
71 These settings should read as follows:
72
73 {{code language="none"}}
74 xwiki.store.attachment.hint = file
75 xwiki.store.attachment.versioning.hint = file
Thomas Mortagne 30.1 76
77 ## Since 9.10RC1
78 xwiki.store.attachment.recyclebin.content.hint=file
79 ## Before 9.10RC1
Vincent Massol 18.1 80 xwiki.store.attachment.recyclebin.hint = file
Thomas Mortagne 26.1 81
Thomas Mortagne 25.1 82 # Attachments being also stored in the deleted documents it's safer to also enable filesystem storage for it too
83 xwiki.store.recyclebin.content.hint = file
Vincent Massol 18.1 84 {{/code}}
85
86 Also make sure they are not commented out.
87
Thomas Mortagne 30.1 88 {{warning}}
89 On XWiki < 9.10RC1, if you already have a wiki and want to take advantage of the Filesystem Attachment Store, you should use the [[snippets:Extension.Filesystem Attachment Porter]] to move your existing attachments onto the filesystem.
90 {{/warning}}
Vincent Massol 19.1 91
AdrianFita 8.1 92 === Filesystem attachment store location ===
93
Manuel Smeria 10.2 94 The directory in which the attachments are stored in the filesystem is defined with the parameter ##environment.permanentDirectory## in the ##xwiki.properties## file. By default it's defined to be ##data##, which is a directory relative to where the Java Servlet Container was started. It's recommend to modify this value to be absolute sure that you can start the Servlet Container from any directory and still have XWiki find the attachments located in this work directory.
AdrianFita 8.1 95
Vincent Massol 9.2 96 For example:
AdrianFita 8.1 97
98 {{code}}
Sergiu Dumitriu 9.6 99 environment.permanentDirectory=/opt/tomcat6/data
AdrianFita 8.1 100 {{/code}}
101
Caleb James DeLisle 1.1 102 === Directory Structure ===
103
AdrianFita 8.1 104 [[image:FilesystemAttachmentStoreDirtree.png||height="300px"]]
Caleb James DeLisle 1.1 105
106 The Filesystem Attachment Store puts your attachments into a directory tree on the hard disk, the directory structure is designed to be intuitive to navigate but you should **never add or remove anything**. Each attachment is accompanied by a piece of meta-data in the database and modifying the content in the filesystem store manually will lead to meta-data with no content or content with no meta-data.
107
108 === Other considerations ===
AdrianFita 8.1 109
Vincent Massol 28.1 110 If you are running a [[cluster>>Documentation.AdminGuide.Clustering.WebHome]] you will need to have a synchronized storage directory for each node. You can use NFS or other means to mount the disk on each node in the cluster.
Caleb James DeLisle 13.2 111
112 ==== Directory cleanup ====
113
Ecaterina Moraru (Valica) 27.1 114 Since [[XWiki 6.0M2>>xwiki:ReleaseNotes.ReleaseNotesXWiki61M2]], it is possible to save time on startup by preventing XWiki from cleaning up empty directories in the Filesystem Attachment Store. To do this, edit ##xwiki.properties## and set **store.fsattach.cleanOnStartup** to false. If you do this, you will be responsible for cleanup of empty directories yourself.

Get Connected