Hi, I'm using a custom fetcher/parser after upgrade (2012-05-30) I got a "Invalid enclosure" for remote attachments.
This is caused by a string concatenation in $destination in feeds/plugins/FeedsParser.inc, FeedsEnclosure::getFile
          $destination .= trim($destination, '/') . '/';
$destination = trim($destination, '/') . '/';

Comments

Thank you muka, this worked for me.

Same issue!

Experienced the same issue, the suggested fix worked for me!

Same problem, Thanks for the fix!

Experienced the same issue, I found (by myself) the same fix.

I just add an additional error message in order to allow search engine to locate more easily this fix.

"The specified file temporary://file could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log."

"Le fichier spécifié temporary://file n'a pas pu être copié car le répertoire de destination n'est pas correctement configuré. Cela peut être dû à un problème de permissions sur le fichier ou le répertoire. Plus d'informations sont disponibles dans la journalisation du système."

Status:Needs work» Closed (duplicate)

Marking as a duplicate of #1611656: Images import doesn't work.

Title:Invalid enclosure due to code errorInvalid enclosure on image import due to code error
Version:7.x-2.0-alpha5» 7.x-2.x-dev
Component:Code» Feeds Import
Priority:Normal» Major
Status:Closed (duplicate)» Reviewed & tested by the community

Reopening this issue and marking #1611656: Images import doesn't work as duplicate since there are more comments here who have confirmed that this fix works for them. Also marking as reviewed and tested unless anyone else has had issues with this fix?

Status:Reviewed & tested by the community» Fixed

This was introduced by #1515204: Malformed destination uri in FeedsEnclosure, I should've noticed, but at that time my testing didn't point any failure.

Committed this.

Worked for me. Thanks!

@Teenage, good idea.

Fix worked for me.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

done this but still invalid enclosure...

Using feeds-7.x-2.0-alpha5

Hi wel3kxial,

Are you on a multi-site install perchance?
I'm on a multi-site install and it's not working for me either.

Thank you.

no I am just sing site install. the code was orignially $destination = trim($destination, '/') . '/';
but still error.

We are send nodes from on site to another via XML. But both sites are on the same stack or in the same docroot.
The problem was in function getFile in FeedsParser.inc.
The function drupal_realpath test was returning that the image file was local because we're on multi-site.
But the file_copy function was unable to find the image file in the site's file folder.
---
I've temporarily 'fixed' it by replacing "if (drupal_realpath($this->getValue()) {" with "if (drupal_realpath($this->getValue()) && strpos($this->getValue(), "http")===false) {".
---
Thank you.
Dave.

I'm getting this same issue on a local install (single site). I successfully imported 707 items, but 176 received the invalid enclosure error. The code is correct in FeedsParser.inc.

I found that my issue was with duplicate file names. Might be something worth checking into.

the original fix worked for me, but in fields where invalid images do not produce an error. it just shows an empty file field with the ? in it on the node.

Fix worked for me.

The fix works for me as well. I'd love to see a new alpha release. It has been a long time since the last alpha release.

I still get this error with the patch

WD Feeds: exception 'Exception' with message 'Download of                                                                   [error]
https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/189062_174985715880515_4388242_n.jpg failed with code 400.' in
/Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsParser.inc:317
Stack trace:
#0 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsParser.inc(373):
FeedsEnclosure->getContent()
#1 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/mappers/file.inc(79):
FeedsEnclosure->getFile('public://')
#2 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsProcessor.inc(450):
file_feeds_set_target(Object(FeedsSource), Object(stdClass), 'field_logo', 'https://fbcdn-s...', Array)
#3 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsProcessor.inc(164):
FeedsProcessor->map(Object(FeedsSource), Object(FeedsParserResult), Object(stdClass))
#4 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/includes/FeedsSource.inc(357):
FeedsProcessor->process(Object(FeedsSource), Object(FeedsParserResult))
#5 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/feeds.module(186):
FeedsSource->import()
#6 [internal function]: feeds_batch('import', 'content_documen...', 0, Array)
#7 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/batch.inc(284): call_user_func_array('feeds_batch', Array)
#8 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/form.inc(4548): _batch_process()
#9 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/install.core.inc(443): batch_process('install.php?pro...',
'http://default/...')
#10 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/install.core.inc(339): install_run_task(Array, Array)
#11 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/install.core.inc(77): install_run_tasks(Array)
#12 /Users/Kurt/Projects/Drupal Projects/drush/commands/core/drupal/site_install.inc(59): install_drupal(Array)
#13 /Users/Kurt/Projects/Drupal Projects/drush/commands/core/site_install.drush.inc(163):
drush_core_site_install_version('vrc', Array)
#14 [internal function]: drush_core_site_install('vrc')
#15 /Users/Kurt/Projects/Drupal Projects/drush/includes/command.inc(332): call_user_func_array('drush_core_site...', Array)
#16 /Users/Kurt/Projects/Drupal Projects/drush/includes/command.inc(198): _drush_invoke_hooks('site-install', Array, 'core')
#17 [internal function]: drush_command('vrc')
#18 /Users/Kurt/Projects/Drupal Projects/drush/includes/command.inc(165): call_user_func_array('drush_command', Array)
#19 /Users/Kurt/Projects/Drupal Projects/drush/drush.php(92): drush_dispatch(Array)
#20 /Users/Kurt/Projects/Drupal Projects/drush/drush.php(61): _drush_bootstrap_and_dispatch()
#21 /Users/Kurt/Projects/Drupal Projects/drush/drush.php(16): drush_main()
#22 {main}
WD Feeds: exception 'Exception' with message 'Invalid enclosure                                                             [error]
https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/189062_174985715880515_4388242_n.jpg' in /Users/Kurt/Projects/Drupal
Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsParser.inc:382
Stack trace:
#0 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/mappers/file.inc(79):
FeedsEnclosure->getFile('public://')
#1 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsProcessor.inc(450):
file_feeds_set_target(Object(FeedsSource), Object(stdClass), 'field_logo', 'https://fbcdn-s...', Array)
#2 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/plugins/FeedsProcessor.inc(164):
FeedsProcessor->map(Object(FeedsSource), Object(FeedsParserResult), Object(stdClass))
#3 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/includes/FeedsSource.inc(357):
FeedsProcessor->process(Object(FeedsSource), Object(FeedsParserResult))
#4 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/profiles/vrc/modules/contrib/feeds/feeds.module(186):
FeedsSource->import()
#5 [internal function]: feeds_batch('import', 'content_documen...', 0, Array)
#6 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/batch.inc(284): call_user_func_array('feeds_batch', Array)
#7 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/form.inc(4548): _batch_process()
#8 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/install.core.inc(443): batch_process('install.php?pro...',
'http://default/...')
#9 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/install.core.inc(339): install_run_task(Array, Array)
#10 /Users/Kurt/Projects/Drupal Projects/vrc.local/html/includes/install.core.inc(77): install_run_tasks(Array)
#11 /Users/Kurt/Projects/Drupal Projects/drush/commands/core/drupal/site_install.inc(59): install_drupal(Array)
#12 /Users/Kurt/Projects/Drupal Projects/drush/commands/core/site_install.drush.inc(163):
drush_core_site_install_version('vrc', Array)
#13 [internal function]: drush_core_site_install('vrc')
#14 /Users/Kurt/Projects/Drupal Projects/drush/includes/command.inc(332): call_user_func_array('drush_core_site...', Array)
#15 /Users/Kurt/Projects/Drupal Projects/drush/includes/command.inc(198): _drush_invoke_hooks('site-install', Array, 'core')
#16 [internal function]: drush_command('vrc')
#17 /Users/Kurt/Projects/Drupal Projects/drush/includes/command.inc(165): call_user_func_array('drush_command', Array)
#18 /Users/Kurt/Projects/Drupal Projects/drush/drush.php(92): drush_dispatch(Array)
#19 /Users/Kurt/Projects/Drupal Projects/drush/drush.php(61): _drush_bootstrap_and_dispatch()
#20 /Users/Kurt/Projects/Drupal Projects/drush/drush.php(16): drush_main()
#21 {main}

When I click that image link, it isn't working for me either, so I think there is just something wrong with the link, not the code.

So my problem is that i am importing from a remote CSV file that got too many broken image urls in it. Is there a good workaround to handle the timeouts? I find it takes too long to finish the import. I noticed that in the code, seems like for each broken link the it will wait 30 seconds until it fails:
curl_setopt($download, CURLOPT_TIMEOUT, variable_get('http_request_timeout', 30));
So by setting the variable http_request_timeout to a lower value will help shorten the import time? And will this have some other impact?

So my problem is that i am importing from a remote CSV file that got too many broken image urls in it. Is there a good workaround to handle the timeouts? I find it takes too long to finish the import. I noticed that in the code, seems like for each broken link the it will wait 30 seconds until it fails:
curl_setopt($download, CURLOPT_TIMEOUT, variable_get('http_request_timeout', 30));
So by setting the variable http_request_timeout to a lower value will help shorten the import time? And will this have some other impact?

So my problem is that i am importing from a remote CSV file that got too many broken image urls in it. Is there a good workaround to handle the timeouts? I find it takes too long to finish the import. I noticed that in the code, seems like for each broken link the it will wait 30 seconds until it fails:
curl_setopt($download, CURLOPT_TIMEOUT, variable_get('http_request_timeout', 30));
So by setting the variable http_request_timeout to a lower value will help shorten the import time? And will this have some other impact?

So my problem is that i am importing from a remote CSV file that got too many broken image urls in it. Is there a good workaround to handle the timeouts? I find it takes too long to finish the import. I noticed that in the code, seems like for each broken link the it will wait 30 seconds until it fails:
curl_setopt($download, CURLOPT_TIMEOUT, variable_get('http_request_timeout', 30));
So by setting the variable http_request_timeout to a lower value will help shorten the import time? And will this have some other impact?

The error is returned pretty quickly, so I don't think that is the problem.

Status:Closed (fixed)» Active

I still get this error as well...

After further testing I noticed the errors don't appear if I change the image fields directory to be specific to the content type.

In case this helps anyone struggling with this. I had this error as well, and after using the temporary fix in #16 (thanks Dave) found this thread :

http://drupal.org/node/1246418

Which is also quoted here : http://api.drupal.org/api/drupal/includes%21file.inc/function/drupal_rea...

Hello,
For local file (with csv), i have a good result with this solution. Surely not the best but some fast.
put your images in the public repertory of Drupal (surely sites/all/files). Create a hook_feeds_after_parse (or rewrite your csv).

CSV IMPORT

/**
  * Invoked after a feed source has been parsed, before it will be processed.
  *
  * @param $source
  *  FeedsSource object that describes the source that has been imported.
  * @param $result
  *   FeedsParserResult object that has been parsed from the source.
  */
function my_module_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
  array_walk($result->items, _reformat_path);
}
/**
* callback function
* @param array $item
* @param type $key
*/
function _reformat_path(&$item, $key) {
    $item['image'] = "public://your_path_to_your_image_in_public;//ex public://import_repository/my_picture.jpg for \sites\default\files\import_repository\my_picture.jpg
}

To escape files doublon

modify feedsParser.inc in line 355 :
$file = file_copy($file, $destination, FILE_EXISTS_REPLACE);

like this drupal don't create another "file". if you read the code, you can see thaht a file_copy is made with is default argument (FILE_EXIST_RENAME), so the file is always rename when a file with the same name exist. This solution is usefull if you have a same image attatch to several content.

Hello,
For images the errors occurs when we have an url like this : http://blogs-images.forbes.com/thumbnails/blog_1370/pt_1370_727_o.jpg?t=...

exception 'Exception' with message 'Invalid enclosure <em class="placeholder">http://blogs-images.forbes.com/thumbnails/blog_2345/pt_2345_1166_o.jpg?t=1362584199</em>' in C:\xampp\htdocs\topnewsspots\sites\all\modules\feeds\plugins\FeedsParser.inc:382
Stack trace:

but if the image ends normally there isn't a problem.

Hi,
I needed to do http://drupal.org/node/1612246#comment-6326658 before it worked!
Can this temporally fix may be become real fix? May be to set this through the GUI that images are local or remote?
Thanks for considering.
Greetings, Martijn

Component:Feeds Import» Code

Hi,

Latest Feeds the change was
from:

if ($this->getValue()) {

to:
if ($this->getValue() && strpos($this->getValue(), "http")===false) {

I am not in position to build patch, please build patch and commit!
Greetings, Martijn

Issue summary:View changes

I have some problems with the parsed data, when I would like to save an image in Drupal from an external source. I use the latest dev release of Feeds 7.x-2.x and Feeds XML Parser.

I relaized that all of the parsed data is structured like that: "\nSOME VALUE\n"

It seems that the file_save_data() can't handle the starting and ending new line and throw an error. If I trim the return value of getValue() method in FeedsElement class, the problem disappears.

Change code
from:

public function getValue() {
  return $this->value;
}

to:

public function getValue() {
  return trim($this->value);
}

Status:Active» Closed (fixed)

This issues was opened 6 months after it was closed. It was a very specific issue that was fixed. Please! don't re-open old issues.

Edit: removed ranting.

Sorry, I didn't realize it was closed. I've created a separated issue for that.