2 title = "Configuring File Uploads"
3 description = "Configuration for files uploads such as images and attachments"
8 BookStack allows users to upload both images for content and files as attachments.
12 **For information relating to security for file uploads please refer to the [Security Page](/docs/admin/security).**
18 Within BookStack there are a few different options for storing files:
20 * [**local**](#local) (Default)
21 - Files are stored on the server running BookStack.
22 - Images are publicly accessible, served by your web-sever.
23 - Attachments are secured behind BookStack's permission control.
24 * [**local_secure**](#local-secure)
25 - Same as local option but images are served by BookStack, with authentication (login required) on image requests.
26 - Is only useful while the BookStack "Public Access" setting is disabled.
27 - More system resource intensive than the default "local" option thus could induce performance issues.
28 - Attachments are secured behind BookStack's permission control.
29 * [**local_secure_restricted**](#local-secure---restricted)
30 - Same as local option but image access is controlled by user access permission to the item an image is uploaded to.
31 - Is the most system resource intensive and could induce performance issues.
32 - Has logical side-affects that can hinder ease-of-use.
33 - Attachments are secured behind BookStack's permission control.
35 - Store files externally on Amazon S3 (or [S3 compatible system](#non-amazon-s3-compatible-services)).
36 - Images are made publicly accessible on upload.
37 - Attachments are secured behind BookStack's permission control, as long as files are not exposed via other means.
39 For all options you can use the 'Enable higher security image uploads' in-app admin setting which appends a random string to each uploaded image name to make URL's hard to guess.
43 This is the default storage mechanism in BookStack that stores uploads on the local filesystem.
44 It can be forced by setting the following in your `.env` file:
50 * Image uploads location: `<bookstack_install_dir>/public/uploads/images`.
51 * Attachment uploads location: `<bookstack_install_dir>/storage/uploads/files`.
55 This storage option stores uploads on the local filesystem but does so in a non-publicly exposed folder,
56 where images are only served from if the user is logged-in to BookStack.
57 The local secure option can be enabled by setting the following in your `.env` file:
60 STORAGE_TYPE=local_secure
63 After setting this option ensure you test system performance creating a page with many images and reload on that page multiple times to ensure your server can keep up with the
64 multitude of image requests.
66 * Image uploads location: `<bookstack_install_dir>/storage/uploads/images`.
67 * Attachment uploads location: `<bookstack_install_dir>/storage/uploads/files`.
69 Refer to the [Migrating to “Secure” Images](#migrating-to-secure-images) for details about switching to this with existing file uploads.
71 #### Local (Secure - Restricted)
73 This option stores uploads on the local filesystem but controls access to image files based upon the
74 user having permission to view the content that the image has been uploaded to.
76 **Note:** This option is relatively new to BookStack and currently considered somewhat experimental.
78 Due to the rather restrictive & granular permission control enforced by this option, various logical scenarios can be encountered
79 that cause image visibility anomalies. For example if a page, with images uploaded to it, is copied to a new page with different
80 visibility permissions, you could have users that are able to see that page but the images within may not load, since their
81 visibility will remain controlled by the original source page. Another example is that deleting a page, where images were uploaded to, will prevent any user access to the related images.
83 This option can be enabled by setting the following in your `.env` file:
86 STORAGE_TYPE=local_secure_restricted
89 After setting this option ensure you test system performance creating a page with many images and reload on that page
90 multiple times to ensure your server can keep up with the multitude of image requests.
92 * Image uploads location: `<bookstack_install_dir>/storage/uploads/images`.
93 * Attachment uploads location: `<bookstack_install_dir>/storage/uploads/files`.
95 Refer to the [Migrating to “Secure” Images](#migrating-to-secure-images) for details about switching to this with existing file uploads.
99 The Amazon S3 option can be enabled by setting the following in your `.env` file:
103 STORAGE_S3_KEY=your-s3-key
104 STORAGE_S3_SECRET=your-s3-secret
105 STORAGE_S3_BUCKET=s3-bucket-name
106 STORAGE_S3_REGION=s3-bucket-region
109 For performance reasons uploaded images are made public upon upload to your S3 bucket and fetched directly by the end user when viewing an image on BookStack. Attachments are not made public and are instead fetched by BookStack upon request. Exact security will depend on the configuration and policies of your bucket.
111 * Image uploads location: `<your_bucket>/uploads/images`.
112 * Attachment uploads location: `<your_bucket>/uploads/files`.
114 By default BookStack will generate a valid Amazon S3 URL for uploaded images. If you'd prefer to use a different URL, that you have pointed at your bucket, you can add the below option to your `.env` file which will be used as a base URL for all image uploads:
117 STORAGE_URL=https://images.example.com
120 #### Non-Amazon, S3 Compatible Services
122 Via the `s3` connection BookStack does support S3-compatible services such as [Minio](https://www.minio.io/). Read the above S3 details to get an idea of general setup.
123 For non-Amazon services the configuration, to be placed in the `.env` file, is a little different:
127 STORAGE_S3_KEY=your-service-key
128 STORAGE_S3_SECRET=your-service-secret-key
129 STORAGE_S3_BUCKET=your-service-bucket-name
131 STORAGE_S3_ENDPOINT=https://your-service-base-endpoint.com:8080
132 STORAGE_URL=https://your-service-base-endpoint.com:8080/your-service-bucket-name
135 Take note of how the first part of the `STORAGE_URL` path is the bucket name. This is important to ensure image URLs are set correctly.
137 BookStack's functionality to set image URL's as publicly accessible will likely not work for third-party services so you'll need to ensure files under the `<your_bucket>/uploads/images` path have policy or permissions to be publicly accessible. If using Minio you can add the following to the bucket policy:
139 
141 #### Separate Image and Attachment Storage
143 If you'd prefer to store images and attachments via different storage options, you can use the below `.env` options to do so:
146 # Image storage system to use
147 # Defaults to the value of STORAGE_TYPE if unset.
148 # Accepts the same values as STORAGE_TYPE.
149 STORAGE_IMAGE_TYPE=local
151 # Attachment storage system to use
152 # Defaults to the value of STORAGE_TYPE if unset.
153 # Accepts the same values as STORAGE_TYPE although 'local' will be forced to 'local_secure'.
154 STORAGE_ATTACHMENT_TYPE=local_secure
159 ### Migrating to "Secure" Images
161 ***Back-up your BookStack instance before attempting any migration***
163 If you are migrating to the `STORAGE_TYPE=local_secure` or `STORAGE_TYPE=local_secure_restricted` options, with existing images, you will need to **move** all content from your previous image storage location (see above) to the `storage/uploads/images` folder within your BookStack instance.
165 **Do not simply copy and leave content** in the `public/uploads/images` as those images will still be publicly accessible.
167 After completing this migration you must re-upload the 'Application Icon' and 'Application Logo' images found in `Settings > Customization`, since these need to remain publicly accessible.
171 ### Changing Upload Limits
173 By default, a lot of server software has strict limits on upload sizes which causes errors when users upload new content. BookStack enforces its own limit but there may also be limits configured as part of PHP and your web sever software. If you run into problems with upload size limits follow the below details for BookStack, PHP and whichever web server you use.
177 The upload limit in BookStack is configured through an option in your `.env` file.
178 Find or add the follow option then configure to your requirements.
182 # Maximum file size, in megabytes, that can be uploaded to the system.
183 FILE_UPLOAD_SIZE_LIMIT=50
188 PHP has two main variables which effect upload limits. Find your `php.ini` file and look for the following variables:
191 * `upload_max_filesize`
193 If the values of these variables are low increase them to something sensible that's not too high to cause issues. Unless you need something higher 10MB is a sensible value to enter for these values:
197 upload_max_filesize = 10M
200 If wanting to upload files over 128MB, you may also need to adjust your PHP memory limit like so:
206 After updating these values ensure you restart your webserver and also PHP if using PHP-FPM or something similar.
210 By default NGINX has a limit of 1MB on file uploads. To change this you will need to set the `client_max_body_size` variable. You can do this either in the http block in your `nginx.conf` file or in the server block set up for BookStack. Here's an example of increasing the limit to 100MB in the http block:
215 client_max_body_size 100m;
216 client_body_timeout 120s; # Default is 60, May need to be increased for very large uploads
221 As per the example above, If you are expecting upload very large files where upload times will exceed 60 seconds you will also need to add the `client_body_timeout` variable with a large value.
223 After updating you NGINX configuration don't forget to restart NGINX. You can test the configuration beforehand with `nginx -t`.
227 Apache does not have any built-in limits which you will need to change but something to note is that if you are using apache and mod_php with `.htaccess` files enabled you may be able to set the above PHP variables in your `.htaccess` file like so:
230 php_value upload_max_filesize 10M
231 php_value post_max_size 10M