admin管理员组文章数量:1296897
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 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?
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/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?
Share Improve this question asked Oct 10, 2013 at 6:17 AtadjAtadj 2,1828 gold badges29 silver badges40 bronze badges 7 | Show 2 more comments10 Answers
Reset to default 22I 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/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:
https://en.support.wordpress/settings/privacy-settings/
Note that it needs to be done from your Wordpress 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:
<wp:attachment_url>http://wpthemetestdata.files.wordpress/2008/06/canola2.jpg</wp:attachment_url>
That file is very clearly available for import. What do your attachment_url files say?
I've been struggling with importing media to wordpress from wordpress 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 and domain2
Go to domain1 -> tools -> export -> media
Now to go domain2 -> 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 pages or posts.
Open the xml file of either, and do a find and replace of domain1 to domain2
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
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.
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 complained Failed 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 );
into wp-config.php
and traced import call into deep. Here is the result:
#0 wp_validate_redirect / wp-includes/http.php:620
#1 allowed_http_request_hosts / wp-includes/class-wp-hook.php:294
#2 WP_Hook->apply_filters / wp-includes/plugin.php:212
#3 apply_filters / wp-includes/http.php:581
#4 wp_http_validate_url / wp-includes/class-http.php:270
#5 WP_Http->request / wp-includes/class-http.php:635
#6 WP_Http->get / wp-includes/http.php:68
#7 wp_safe_remote_get / wp-content/plugins/wordpress-importer/class-wp-import.php:1008
#8 WP_Import->fetch_remote_file / wp-content/plugins/wordpress-importer/class-wp-import.php:954
#9 WP_Import->process_attachment / wp-content/plugins/wordpress-importer/class-wp-import.php:697
#10 WP_Import->process_posts / wp-content/plugins/wordpress-importer/class-wp-import.php:88
#11 WP_Import->import / phar:.../Import_Command.php:179
#12 Import_Command->import_wxr / phar:.../Import_Command.php:81
Solution 1
Add following lines into wp-content/themes/{your theme}/functions.php:
add_filter("http_request_host_is_external", function($allow, $host, $url){
if (gethostbyname($host) == "your_hostname") {
$allow = true;
}
return $allow;
}, 10, 3);
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:
wp option update home your_hostname
本文标签: exportFailed to import Media
版权声明:本文标题:export - Failed to import Media 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741629952a2389302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
IMPORT_DEBUG
and set it totrue
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 Commented Oct 19, 2015 at 20:40IMPORT_DEBUG
option – kimliv Commented Jun 11, 2016 at 9:34define ( 'IMPORT_DEBUG', true );
. – Mark Commented Jun 12, 2016 at 12:40xml
URLs are onhttps
, editing thexml
files to togglehttps
tohttp
helped. – Ismail Commented Dec 10, 2016 at 17:15