Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Drupal 11.3.18 — Update released for Drupal core (11.3.18)! Release: Geocoder 8.x-4.38 — Minor update available for module geocoder (8.x-4.38). Release: UI Icons 2.0.1 — Minor update available for module ui_icons (2.0.1). Release: Vite 1.5.7 — Minor update available for module vite (1.5.7). Release: SearchStax Studio โ€“ Site Search 1.13.0 — Minor update available for module searchstax (1.13.0). Release: Prototype: Select 2.0.3 — Minor update available for module prototype_select (2.0.3). Release: Prototype: Select 2.0.2 — Minor update available for module prototype_select (2.0.2). Release: Prototype: Select 2.0.1 — Minor update available for module prototype_select (2.0.1). Usage Milestone: Element Class Formatter — Module element_class_formatter crossed 1,000 active installs. Module Revived: Anti-Duplicates 4.3.0 — Module anti_duplicates updated after 13 months of inactivity (4.3.0).

This module provides a dedicated preview page for attached files, rendering Markdown as formatted text, and CSV/TSV files as tables. Previews are only available to users who can download the original file and respect file access permissions. Additional file types can be supported through plugins.

Attachment Preview gives each attached file a page of its own, at /file/ID/preview. A Markdown file is rendered, a CSV or TSV file is shown as a table, and a button downloads the original. The page is shown only to users who may download the file, and other modules add file types with a plugin.

Features

  • ๐Ÿ”’ Access checked as for the download. The preview page opens only when the file may be downloaded: the file's own download access, and no hook_file_download() implementation denying it. A user who gets a 403 on a private file gets a 403 on its preview too.
  • ๐Ÿ“ Markdown through a text format. A Markdown file is rendered by a text format you choose, with the filter of Markdown or Markdown Easy, so the site's own filters, such as code highlighting, run on it too. A format in which nothing limits HTML after the Markdown filter cannot be chosen, and the check is repeated on every preview.
  • ๐Ÿงฎ CSV and TSV as a table. The delimiter and the encoding (UTF-8 or Windows-1252) are detected, the first row can be the header, and only the first rows and columns are read, 200 and 50 by default. HTML in a cell is shown as text.
  • ๐Ÿ“ A size limit before anything is read. A file above the limit, 10 MB by default, is never opened: its page offers the download only. The size is taken from the file on disk.
  • โšก Cached per file, written nowhere. The preview is kept in the render cache for each file and rebuilt when the file or the settings change. No converted copy is saved, and the preview of a private file is never stored in the page cache.
  • ๐Ÿ”— Linked where files are listed. Choose the Link to preview format for a file field, or turn on one setting that points every file link of a previewable type at its preview, in any field, view or template that renders files as file links.
  • ๐Ÿ”Œ A plugin per file type. Another module adds a type with an AttachmentPreviewer plugin, which receives the file only after access and the size limit were checked and returns a render array.

Quick start

composer require drupal/attachment_preview:1.0.x-dev@dev
drush en attachment_preview
  1. Open Configuration > Media > Attachment Preview. CSV and TSV is already enabled.
  2. For Markdown, create a text format with no roles, with the Markdown filter of Markdown or Markdown Easy followed by Limit allowed HTML tags and correct faulty HTML. Then enable Markdown on the settings page and choose that format.
  3. In Manage display of a content type, set a file field's format to Link to preview, or turn on Link every previewable file to its preview.
  4. Open a page with an attached .md or .csv file and click it: its preview opens, with the Download button above it.

A CSV file as a table, here set to show 12 rows. The rest of the file is in the download.

Good to know

  • The preview follows the download. A file in the public file system can be downloaded by anyone who has its address, and so can its preview; a private file's preview needs the same access as its download. A permanent private file that nothing references is not previewed, even to its owner.
  • The module does not convert Markdown itself: a Markdown filter module is required for Markdown files. With the Markdown module, set the parser's render strategy as the README explains, or its default strategy renders the file as plain text.
  • Links printed straight into a template, without the file link theme hook, are not changed. They can point at the attachment_preview.preview route.
  • The preview takes the theme's look: it carries the text-content class that Olivero styles, and the module's own rules for tables and code blocks apply only where the theme has none.

Additional requirements

  • Drupal 10.3 or later, or Drupal 11, with the File and Filter modules from core.
  • league/csv 9.28 or later, installed by Composer with the module.
  • For Markdown files: a module that provides a Markdown filter, such as Markdown Easy or Markdown.

Recommended modules/libraries

  • Markdown Easy: a Markdown filter on CommonMark that itself requires the HTML limit to run after it, which is the order a preview format needs.
  • Markdown: a Markdown filter with a choice of parsers and extensions.

Similar projects

  • Viewer imports CSV, XLSX and PDF files from uploads, URLs or FTP and presents them with its own plugins, such as charts and DataTables, through a reference field or a block. Pick it to publish data files as charts and tables; pick Attachment Preview to open the files already attached to your content.
  • CSVFile Formatter and File Field Table Formatter show a CSV file field as a table in the entity's own page. Pick one of them for the table in the page; pick Attachment Preview for a page per file, and for other file types.
  • Markdown field formatter shows a Markdown file field as HTML in the entity's own page, on Drupal 10 at most.

Community documentation

  • README: every setting, the text format for Markdown, how access and caching work, and how to write a previewer.

Supporting this module

Developed and maintained by Bloomidea. Bloomidea offers support and custom development for this module.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Sep 2026
Latest release
6 hours ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core Release date
1.0.x-dev Dev 10โ€“11 Sep 29, 2026