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?
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: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
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:
Relevant WordPress documentation:
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).
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:
That file is very clearly available for import. What do your attachment_url files say?
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
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.
I finally figured it out.
Let’s say we have domain1.com and domain2.com
Go to domain1.com -> tools -> export -> media
Now to go domain2.com -> tools -> import (upload xml file of media export)
Make sure you check download and import file attachments.
This will take a while. While it’s running, we will do the export of domain1.com pages or posts.
Open the xml file of either, and do a find and replace of domain1.com to domain2.com
Now if the other import finished, start the upload of that modified xml export, and guess what, it will now reference the uploaded images you did in the previous import.
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.
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
Go to line
566
and comment out the following code block.Once you comment those two lines out, go in and add the following line.
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.
In my case I was trying to move a site from one hosing location to another. The new hosting had internally set the IP for the domain to its own server (obviously), after changing that to the old server the migrator knew where to look for the files.
I used wp-cli to import media from another site.
wp import
always complainedFailed to import Media xxxx: Request failed due to an error: A valid URL was not provided. (http_request_failed)
and imported nothing.I enabled debug by adding
define( 'IMPORT_DEBUG', true );
intowp-config.php
and traced import call into deep. Here is the result:Solution 1
Add following lines into wp-content/themes/{your theme}/functions.php:
It enables HTTP request to original site.
Solution 2
Admin panel / Settings / General / Site Address (URL) – here put URL of the original site. Or use wp-cli: