How to Fix the “Failed to import Media” Error in WordPress

Updated on May 11, 2023

The WordPress Importer plugin is used to move content from one WordPress installation to another. It transfers all of your posts, pages, custom post types, and media uploaded to the media library from the previous installation to the new one. The plugin can also be used to migrate your content from Blogger, LiveJournal, or Tumblr to a new WordPress page.

The error "Failed to import Media" can occur in rare cases. The error indicates that WordPress was unable to retrieve the media from the old source in order to upload it to your WordPress installation, where you wish to import it. This article will explain why this can happen and how to resolve the issue causing the error.

This post includes:

Enable Debugging Mode for WordPress Importer

WordPress Importer displays an error message such as "Failed to import media "image-name" by default. This does not help you further debug the error, but you can enable debugging mode to get a more detailed error message.

  • Open your FTP client and connect to your website. You can also use the File Manager in cPanel:
  • Find a file called wp-config.php in the root directory of the files of your website. We need to edit it:
  • Insert the following line of code in a new line after <?php to enable the debugging mode and save the file:
    • define( 'IMPORT_DEBUG', true );
  • Try to import the XML file again with WordPress Importer. Now you should get an error message for all failed imports with a little more information that will help you find the root of the problem.

Do not forget to remove this line of code when you have solved your problem.

Is the Media Source Still Available?

In the XML file you upload to WordPress Importer, there is only the reference (URL) to the file, not the file itself. This means that the importer tries to download e.g. the image from the old website/blog. If the old source is no longer available, the importer plugin cannot download the file and throws an error.

To check if the media is still available, we can simply open it in your browser. To find the URL of the media, open the XML file you would upload in a text editor. It should contain code that looks like this:

<pubDate>Fri, 02 Dec 2022 22:00:15 +0000</pubDate& <dc:creator><![CDATA[example]]></dc:creator& <guid isPermaLink="false"></guid& <description></description& <content:encoded><![CDATA[]]></content:encoded& <excerpt:encoded><![CDATA[]]></excerpt:encoded& <wp:post_id>20</wp:post_id& <wp:post_date><![CDATA[2022-12-02 22:00:15]]></wp:post_date&
<wp:post_date_gmt><![CDATA[2020-12-02 22:00:15]]></wp:post_date_gmt&
<wp:comment_status><![CDATA[open]]></wp:comment_status& <wp:ping_status><![CDATA[closed]]></wp:ping_status& <wp:post_name><![CDATA[example-image-110849_1280-2]]></wp:post_name& <wp:status><![CDATA[inherit]]></wp:status& <wp:post_parent>0</wp:post_parent& <wp:menu_order>0</wp:menu_order& <wp:post_type><![CDATA[attachment]]></wp:post_type& <wp:post_password><![CDATA[]]></wp:post_password& <wp:is_sticky>0</wp:is_sticky& <wp:attachment_url><![CDATA[]]></wp:attachment_url& </item&

The important property of each <item> element is the <wp:attachment_url>. It contains the URL of the media in the old source. In this example, the URL calls, which you can open in your browser and check if the file is accessible.

If the file is not accessible, you have to make sure that you can access it again and run the WordPress importer afterward.

Does WordPress Have Write-permissions for Media Files That Should Be Transferred?

Another possibility is that the WordPress Importer plugin can download the file from the old source but not save it to the new WordPress instance. The most common cause of this behavior is a lack of permission to write to the wp-content/uploads/ folder.

You can easily test this by uploading a file to your new WordPress website's media library. If you can't upload an image there, you can be pretty sure you don't have enough permissions.

Solve this problem by following these simple steps:

  • Open your FTP client and connect to your website. You can also use the cPanel File Manager.
  • Navigate to the wp-content/ folder. Here you should find an uploads/ folder.
  • You should change the permissions of this folder recursively. Set the permissions for this folder, all subfolders, and files to 755.
  • Try again to see if you can upload a file to your media library and import the media using the WordPress importer.

If that doesn't work and you still can't upload files, change the permissions to 777, but be cautious because, depending on the server's configuration, this could be a potential security hole. If it only works with 777, please get in touch with your web host to discuss this further.

Can You Transfer Media From One Server to Another?

One final tip from us occurs only in exceptional circumstances. WordPress Import may fail if you attempt to move your website from one server to another. For example, if you host and on the same server/webspace with the exact same IP address, a WordPress hook called HTTP request-host is external may prevent the media file from being downloaded. More information about this issue can be found in this Stackoverflow thread.

You can solve this problem by disabling the check if the file comes from an external source. To do this, navigate via the cPanel File manager to the theme you have activated, e.g. wp-content/themes/divi/. You should find a functions.php file there. You have to open the file in an editor and add the following line of code after <?php in a new line.

add_filter( 'http_request_host_is_external', '__return_true' );

After you add this line of code to the file, you should try to import the media files again. Do not forget to remove this line of code when you have solved your problem.

What to Do After a Successful Import

We hope that one of the above-mentioned solutions is the solution to your problem. You may already be aware of how simple WordPress's media library is. You have all uploaded files in a list or grid view - that's all there is to it. You can't organize your uploads if you really want to. T add more functionality, install a plugin like Real Media Library, which adds a full-featured file and folder manager to your WordPress installation. It greatly aids in the organization of your uploads and saves time later when searching for uploads.

We hope you find this article useful. Discover more about FastCloud - the top-rated Hosting Solutions for personal and small business websites in four consecutive years by the HostAdvice Community!

WordPress Hosting

  • Free WordPress Installation
  • 24/7 WordPress Support
  • Free Domain Transfer
  • Hack-free Protection
  • Fast SSD Storage
  • Free WordPress Transfer
  • Free CloudFlare CDN
  • Immediate Activation
View More