Prevent Drupal Headaches

FLEXIBLE FILE PATHS
FROM THE START

Wednesday, January 15, 14
training.acquia.com/events

Wednesday, January 15, 14
Who is this for?
•
•

New to Drupal?

•

Inherited a new
Drupal site and want
to know more about
configuration

Starting a new Drupal
site!

Wednesday, January 15, 14
In this demo
•

How file path patterns
affect maintenance and
migrations

•

File upload
management

•

Future friendly path
patterns

Wednesday, January 15, 14
Source of the pain?
•

Drupal default file
field upload pops
ALL files into the
same directory

•

Often overlooked by
developers

•

Significant
performance impact

•
•

Easy to prevent!
...not easy to fix!

Wednesday, January 15, 14
Wednesday, January 15, 14
A future fix

https://drupal.org/node/2128055
Wednesday, January 15, 14
Not in this demo
• Check out these blog posts
• Adding images to your site
• Inline images in Drupal 7
• Responsive or Adaptive images in Drupal 7
• Inline and responsive images in Drupal 8

Wednesday, January 15, 14
A clean room
• Protips!
• Many potential conflicts with other modules

that control file system. Use clean testing
sites.
• See Create a Test Site | Drupal.org

Wednesday, January 15, 14
Getting to grip with the basics

Out of the box file
handling

Wednesday, January 15, 14
Basic settings
•

Global settings

•
•
•

Display options
Upload destination
Per content type settings

•
•
•
•
•
•
•
•

Required?
Help text
Allowed extensions
File directory
Upload size
Description field
Progress indicator
Number of values

Wednesday, January 15, 14
Limiting file types
• Security tip: Err on the side of less file

extensions available to the least amount of
users

Wednesday, January 15, 14
Description field setting

Wednesday, January 15, 14
The description

Wednesday, January 15, 14
Compare
Without “description”

Wednesday, January 15, 14

With “description”
The “display” option
Display enabled

Wednesday, January 15, 14

Display disabled
Manage field display

Wednesday, January 15, 14
Field report!

Wednesday, January 15, 14
Transliteration
• You NEED transliteration. Install it.
• Configuration > Media > File system
•

Wednesday, January 15, 14
Transliteration
• Configuration > Search and metadata > URL

aliases > URL aliases

Wednesday, January 15, 14
Fix existing file names

Wednesday, January 15, 14
How many is too
many?

Wednesday, January 15, 14
The extreme limits
• FAT32:
• Maximum number of files: 268,435,437
• Maximum file size: 4GB
• maximum number of files per directory: up to 65535, or less depending
•
•
•
•
•
•
•
•
•
•

on file names
NTFS:
Maximum number of files: 4,294,967,295
Maximum file size: 16TB currently (16EB theoretically)
Ext2:
Maximum number of files: 10¹⁸
Maximum file size: 2TB
theoretical file per directory limit: 1.3 × 10²⁰ files
Ext3:
Maximum number of files: number of bytes in volume/2¹³.
Maximum file size: 16GB (1KB block) to 2TB (4KB block)

•

http://stackoverflow.com/questions/466521/how-manyfiles-in-a-directory-is-too-many
Wednesday, January 15, 14
What’s wrong?
• Slow to load directory for maintenance and

migration
• Performance hit loading files from that

directory
• Set Max at 1000 or 100,000- well below your

“limit”

Wednesday, January 15, 14
File path patterns

Wednesday, January 15, 14
Configure file paths
•

Basic settings are
limited

•
•

arbitary text
entitytype/filetype

•

Example:
article/pdfs

Wednesday, January 15, 14
A better idea!
• sites/default/files/YYYY/MM/DD
• For high volume uploads

https://drupal.org/node/2128055
Wednesday, January 15, 14
Token for file directory!
• Set to date

Wednesday, January 15, 14
File (Field) Paths
• Set file name also
• Node tokens
• Transliteration

Wednesday, January 15, 14
Example file path patterns
• Parent directory by date
• Parent directory by content type
• Parent directory by a combination of content

type and author

Wednesday, January 15, 14
Pathauto
• Requires Token
• Set patterns for paths instead of node/1

Wednesday, January 15, 14
Private and
public files

Wednesday, January 15, 14
public:// & private://
•
•

Public

•
•

Private

Anyone can
download them

Controlling access to
the files

Wednesday, January 15, 14
Private
• Specify a directory

• OR Sub-directory

outside of the doc
root folder

under the public
directory

Example

Example

../private

sites/default/
files/private

https://drupal.org/documentation/modules/file

Wednesday, January 15, 14
Private directory
• Create the private directory at same level as

root folder
• Configuration > Media > File system
• Set file system path

• System creates .htaccess file

Wednesday, January 15, 14
Choose default option
• Configuration > Media > File system
• Choose default method

Wednesday, January 15, 14
Per field options
• Select private file

• The paths will be like

/system/files/ebooks/pressrelease.pdf

Wednesday, January 15, 14
What happens?
• Field inherits access publishing settings of

content

Wednesday, January 15, 14
Private file modules
• Private files download permission 1.7k using
• Field Permissions 36k using
• File entity (fieldable files) 29k using

Wednesday, January 15, 14
More complex file
handling needed?

Wednesday, January 15, 14
A flexible solution
•
•
•
•

Media +

•

Being used in Drupal
Commons and Demo
Framework

File entity +
OEmbed +
CKEditor

Wednesday, January 15, 14
Demo Framework
• A good example of media configuration
• http://drupal.org/project/df

Wednesday, January 15, 14
CKEditor Link

https://drupal.org/project/ckeditor_link_file
https://drupal.org/project/ckeditor_link
Wednesday, January 15, 14
Multi file uploads
• http://drupal.org/project/

multiupload_filefield_widget
• http://drupal.org/project/

multiupload_imagefield_widget
• http://drupal.org/project/plupload

Wednesday, January 15, 14
Future friendly

Wednesday, January 15, 14
Media module 2.x
• Adds an upload widget

Wednesday, January 15, 14
File entity
• File entity (fieldable files)
• Add fields to files, group, add display modes,

use Token
• Working on getting this into D8

• Documentation at drupal.org/node/1591498

Wednesday, January 15, 14
Fieldable entity

Wednesday, January 15, 14
File browser
• File browser and uploader

Wednesday, January 15, 14
File settings (global)
•

Configuration »
Media » File
settings

•

Global file field
settings

Wednesday, January 15, 14
Granular file permissions

Wednesday, January 15, 14
Display formatter

Wednesday, January 15, 14
Further extend
• Media module - Handing files from external

sources and services such as YouTube,
Vimeo and Flickr.
• File entity revisions module

Wednesday, January 15, 14
Plans to bring into D8
• Find out more “Drupal 8 media battle-plan”

groups.drupal.org/node/384813
• drupal.org/community-initiatives/drupal-core/

file-management

Wednesday, January 15, 14
Display formatting
• Additional display formatters

Wednesday, January 15, 14
Display formatting

Wednesday, January 15, 14
File view modes

Wednesday, January 15, 14
Fix it? HALP!

Wednesday, January 15, 14
Remediation
• Move files to new directories
• Recreate all the files using your new tokens
• If you embed “inline” files/images, you’d

have to write a script to find and replace.
• Public files are easier.
• Drupal handled files are easier.
• Example: Media is embedding a file ID.

Wednesday, January 15, 14
Migrate Module
• Use Migrate module to do an in-place

migrate of your own site.

drupal.org/project/migrate
Wednesday, January 15, 14
Professional help
• Acquia Professional Services
• Migration services

Wednesday, January 15, 14
acquia.com/resources/webinars/
preventing-drupal-headaches-content-type-checklist
Wednesday, January 15, 14

Preventing Drupal Headaches: Establishing Flexible File Paths From The Start