Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

migrate_file_to_media

1,315 sites Security covered
View on drupal.org
Migrate File Entities to Media Entities

This module allows you to migrate file entities to media entities using the migrate module.

Lately, also support for Drupal 7 entities was added.

Main features:

  • While migrating the files, a binary hash of all images is calculated and duplicate files are recognized. If the same file was uploaded multiple times, only one media entity will be created.
  • Migration of translated file/image fields is supported. Having different images per language will create a translated media entity with the corresponding image.
  • Using migrate module allows drush processing, rollback and track changes.

Usage

Preparation: Install media core module

Before you can start, you need to install the media module of Drupal Core. This will automatically create 5 media bundle types for you: Image, Document, Video, Remote video and Audio. Media Library is a handy module here.

Generate the target media fields

Generate the media fields based on the existing file fields using the following drush command:

drush migrate:file-media-fields <entity_type> <bundle> <source_field_type> <target_media_bundle>

Example

drush migrate:file-media-fields node article image image

For all file fields the corresponding media entity reference fields will be automatically created suffixed by _media.

Create a custom migration per content type

  • Create a custom module. It could be based on the migrate_file_to_media_example module (optional)
  • Create your custom migration templates using the included yml generator.
  • The module supports nodes and also paragraphs and any other entity type as a source bundle.

Generate command:

drush generate mf2m_media

Example of the result:

Welcome to mf2m_media generator!
–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
 Module machine name:
  ➤ migrate_file_to_media_example

The generator will ask you several questions about the module, the source bundle and the target media entity. It will generate several files based on your answers, that can be used to migrate the files to media entity.

Explanation of the generated migration files is in the README.md

Refresh / check migrations

If you created a new module with the generator, you can just enable the module and the migrations will be visible when running drush ms. If you generated the migration files into an existing module, you will have to install the module config_devel and update your mymodule.info.yml file. You can find a nice documentation about config_devel here: https://drupal.stackexchange.com/questions/191435/how-to-refresh-new-mig...

Prepare duplicate file detection

In order to detect duplicate files / images, run the following drush command to calculate a binary hash for all files. The data will be saved to the table "migrate_file_to_media_mapping". You need to run this drush command before you can import media entities.

drush migrate:duplicate-file-detection <migration_name>

(optional step): Check for existing medias

Sometimes you already have media entities in your database or you have multiple migrations and would like to avoid duplicate media entities. Here is the solution:

  1. Run the command drush migrate:duplicate-media-detection image --all. (see drush help migrate:duplicate-media-detection for extra options)
  2. Run the duplicate file detection for step 1 of your file migration: drush migrate:duplicate-file-detection <migration_name> --check-existing-media
  3. Run step 1 and 2 of your file migrations as described on the project page or the readme.

Migrate the images to media entities

Check the migrations using

drush migrate:status

Run the migrations using

drush migrate:import <migration_name>

Activity

Total releases
1
First release
Feb 2026
Latest release
2 months ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
2.0.15 Stable Feb 13, 2026