12

When I generate XML file with [Tools > Export] and use [Tools > Import] on another WordPress website I get "Failed to import Media" for each attachment post type. And images that failed to load are hotlinked from the previous server which consumes the transfer of that previous server...

But when I download "Unit Test" from http://codex.wordpress.org/Theme_Unit_Test then this problem doesn't exist. Some images still have "Failed to import Media" but it's only like 5 out of 30 images. They have URLs to their own server in their XML but somehow [Tools > Import] manages to download their media and replace these URLs with new locations (it is not hotlinked anymore).

What's the trick to make it work properly without "Failed to import Media"? Why even "Unit Test" has a few "Failed to import Media" messages?

  • As the server where you import needs to get them from the old location you should not only check if the files are at the old server, but also if the new server can fetch them. Maybe something limits outbound requests. Have you tried importing it on another server or localhost? I am afraid this could be a very localised issue. – kraftner Jun 6 '14 at 15:49
  • 1
    As of WordPress 4.3.1 (possibly earlier) you can define IMPORT_DEBUG and set it to true to get meaningful feedback instead of just "Failed to import media". I can't imagine why this isn't default behavior. That may help narrow your problem down if the weather is just right. – Mark Oct 19 '15 at 20:40
  • @Mark in which file can I set the IMPORT_DEBUGoption – kimliv Jun 11 '16 at 9:34
  • 1
    @kimliv: you'll want to stick this in wp-config.php at the root of your WordPress install: define ( 'IMPORT_DEBUG', true );. – Mark Jun 12 '16 at 12:40
  • Sorry for bumping, had the same issue and the original site from which I import had SSL not working and the xml URLs are on https, editing the xml files to toggle https to http helped. – Samuel Elh Dec 10 '16 at 17:15
10

I had a very similar problem when I moved a WordPress Blog from a single WordPress installation to a Multisite installation with different domain names but same IP.
I found out that the problem is the wp_http_validate_url function which drops the URL if the source IP is the same as the destination IP.
You can add a filter wp_http_validate_url to prevent this and allow matching source and destination IPs:

add_filter( 'http_request_host_is_external', '__return_true' );

Please see this answer for detailed explanation of the filter hook and why you should remove it after the import: https://wordpress.stackexchange.com/a/123313/75573

  • I spent close to 5 hours trying to import my posts with their images and this solved it. – Jonny Jun 19 at 16:54
1

When you generated your export file, was it on a live server or a localhost? Is that web page still accessable? If the media import fails, it means the images, as linked out of the XML, are coming up 404.

Open up the XML file and see where the images are pointing. If we open up the Theme Unit XML file, we will see lines like this:

<wp:attachment_url>http://wpthemetestdata.files.wordpress.com/2008/06/canola2.jpg</wp:attachment_url>

That file is very clearly available for import. What do your attachment_url files say?

  • 1
    I mentioned "And images that failed to load are hotlinked from the previous server which consumes the transfer of that previous server..." which indicates that images do not return 404, they are not on localhost but they still generate "Failed to import Media". My <wp:attachment_url> says example.com/2008/06/image.jpg too where example.com is always accessible domain. That's why I'm asking this question :) It clearly doesn't work even if images do not generate 404. It even doesn't work with wpthemetestdata.files.wordpress.com occasionally (~5 random images out of 30 fail). – Paul Oct 10 '13 at 7:53
  • Right, sorry, my mind is a bit burned out at this point in the night. Do you have some kind of hotlink protection on the server? – Imperative Ideas Oct 10 '13 at 8:19
  • 1
    Nope, it's publicly accessible server with publicly accessible images, no protection whatsoever. But even if there was some protection, WordPress's server does the same thing occasionally. Does it mean that this importer is just buggy? – Paul Oct 10 '13 at 8:35
  • That or one of the servers has an obnoxiously short timeout value. I'm fresh out of ideas for you. Does the XML import properly to Localhost? If so, you can sort of cheat... do the import locally then use WP Migrate DB and clone the result to live. – Imperative Ideas Oct 10 '13 at 8:57
1

I've been struggling with importing media to wordpress.org from wordpress.com as well. I managed to import all posts however images were still linked to the old site. I was nearly crying as I realised the only solution was to manually download and upload over 200 large images post by post (exporting/importing smaller portions of posts didn't work either).

After testing some plugins I found one that actually imports your wordpress media automatically. I couldn't believe but it actually does work. You have to go post by post but still it's better than manual download and upload. Here is the link if anyone is interested

1

Make sure your site isn't set to "Private".

When you export your Wordpress blog, all the textual content is embedded in the resulting XML file. All the binary content (pictures, file attachments etc) are exported as URLs pointing to their location on the existing blog. This is why when you import from a private Wordpress blog you will still be able to import all the posts/etc but all the images/etc will fail.

Here is where you need to change the setting as of the curent (2017-06-19) version:

enter image description here

Relevant Wordpress documentation:

https://en.support.wordpress.com/settings/privacy-settings/

Note that it needs to be done from your Wordpress.com account's settings, not from the settings of the blog itself, which is another potential point of confusion (and frustration).

1

This issue can happen when using certain plugins on the remote/local site.

Ideally, disable all plugins on both sites before exporting or importing, then reactivate them after the process is complete.

If you are trying to avoid disabling ALL plugins, then at least deactivate any plugins that affect images or image handling ... the most common type would probably be those that do image optimization.

In my case, I had EWWW Image Optimizer (which I highly recommend) active on the local site, and it caused this error. I disabled it, ran the import successfully, and reactivated it.

0

I had the same problem and after hours of searching and testing the problem was that the source server was blocking image downloads because of "Hotlink Protection" being active in the cPanel.

  • You're right. In my case I realized that I implemented a hotlink protection in my .htaccess. Other cases are cPanel or Cloudflare. – John Doe Mar 22 at 22:10
0

For those that don't want to use add_filter or have no idea how to integrate it without creating a separate module. Here is a quick handy trick to get it done.

Open this file

vim ./wp-includes/http.php

Go to line 566 and comment out the following code block.

if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) )
  return false;

Once you comment those two lines out, go in and add the following line.

return true;

Go ahead and save the file and upload the XML file to try again. You will now download all the related content. Go back an remove the comment block and the return statement and you are good to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.