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

pedrop’s picture

Thank you muka, this worked for me.

5n00py’s picture

Same issue!

conantp’s picture

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

wolffereast’s picture

Same problem, Thanks for the fix!

Anonymous’s picture

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."

coreyp_1’s picture

Status: Needs work » Closed (duplicate)

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

Rob_Feature’s picture

Title: Invalid enclosure due to code error » Invalid 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?

franz’s picture

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.

p55mac’s picture

Worked for me. Thanks!

@Teenage, good idea.

kdhartstrom’s picture

Fix worked for me.

Status: Fixed » Closed (fixed)

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

wel3kxial’s picture

done this but still invalid enclosure...

wel3kxial’s picture

Using feeds-7.x-2.0-alpha5

dallen’s picture

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.

wel3kxial’s picture

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

dallen’s picture

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.

MrPeanut’s picture

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.

BiigNiick’s picture

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.

enricotersi’s picture

Fix worked for me.

Jorrit’s picture

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.

kurtzhong’s picture

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}
Jorrit’s picture

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.

kurtzhong’s picture

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?

kurtzhong’s picture

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?

kurtzhong’s picture

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?

kurtzhong’s picture

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?

Jorrit’s picture

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

walker2238’s picture

Status: Closed (fixed) » Active

I still get this error as well...

walker2238’s picture

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

glynnr’s picture

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...

salade-de-phalanges’s picture

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.

ieta_maher’s picture

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.

Summit’s picture

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

Summit’s picture

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

k.dani’s picture

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);
}
twistor’s picture

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.

k.dani’s picture

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

chefnelone’s picture

Is this commited to dev? If not, where is fix?

WSVereen’s picture

Late to the discussion here but I am verifying that the original solution did not work for me as the code already had been changed as other users had stated. I did find a solution to the invalid enclosure problem by adding a Feeds Tamper plugin of Strip Tags to the image field.

ethanhinson’s picture

#16 worked for me! Based on the documentation for drupal_realpath, a different check should be used to determine the location (ie local vs remote) for files.

CyberBizness’s picture

I replace the line 348 of FeedsParser.inc by :

if (drupal_realpath($this->getValue()) && !(stripos($this->getValue(), "http:")>-1) && !(stripos($this->getValue(), "http:")>-1) ) {

and it's ok for me ;-) C'est peut-être pas "élégant". But it works!

- stripos instead of strpos (just in case http is in capitals)
- "http:" instead of "http", cause some files may have "http" somewhere in their name.. or path.
- added a stripos for "https:"
- compare integer returned value instead of using bolean value

*** And make sure you don't have any 401 error regarding basic authentification.

and commented out line 378 : $destination = trim($destination, '/') . '/';

nazarioa’s picture

So I just ran into this issue with version '7.x-2.0-beta1' of the module.
I altered the module's code per Summit's description (from almost two years ago) and it worked like a charm.

public function getValue() {
  return trim($this->value);
} 
molenick’s picture

I'm also getting this error with 7.x-2.0-beta1, it pops out on line 407 of FeedsParser.inc.

I tried @nazarioa's change but it wasn't enough - the full error showed that a %20 was being prepended to my url. I did a quick and dirty test of replacing 407 to:

  // Very dirty, will break if %20 is anywhere in the path
  $result = http_request_get(str_replace("%20", '', trim($this->getUrlEncodedValue())));

This is a multisite install, which I'm mentioning because others had a similar problem much earlier. Not sure why the %20 or whitespace is getting prepended, it's not in the original data source.

helmo’s picture

The separate issue @k.dani mentions in #37 is #2202817: New line in parsed url breaks image saving

I've posted a patch there to continue the discussion.