Ok So I am trying to import nodes with remote file export method but somehow URLS in var export are not correct. This is what it looks like

Could not open 'http://croaziadentisti.it/public%3A//zub1.png' for reading.

seems like "files" directrory variables is not passed like it should be and instead some "public%3A/" token is here and ofcourse it doesn't work then. Any ideas why this is so?

Comments

markosef’s picture

This is export data excerpt

            'filename' => 'dentivo.jpg',
            'uri' => 'public://dentivo.jpg',
            'filemime' => 'image/jpeg',

and file_default_scheme() function also gives public:/ if checked in node_export.module around

              // Remote export mode
              elseif ($export_mode == 'remote') {				  
                $export_data = url($file->uri, array('absolute' => TRUE));
				dpm(file_default_scheme() . ':/'  );
              }

I checked this at two locations one is the drupal ugprade from 6 to 7, other is a multisite setting, both drupal sites work fine but are a bit complex.

Anyway. What I did is a hack to fix this as I counldn't locate where does problem come from. I rewrote how file path is constructed with one line and it works now.

              // Remote export mode
              elseif ($export_mode == 'remote') {
				 $file->uri = 'sites/default/files/'. $file->filename;
                $export_data = url($file->uri, array('absolute' => TRUE))

So maybe this could help someone. Also suggestion to module maintainter to add a "default" variable for path when exporting, this could solve possible cases like this if someone else has the same problem. But then again maybe it is a bug for everyone :-)

im0000’s picture

Thanks, it works for me, and I found a better way

// Remote export mode
              elseif ($export_mode == 'remote') {
                $file_public_path = variable_get('file_public_path', conf_path() . '/files');
                $file->uri = str_replace('public://', $file_public_path."/", $file->uri);
                $export_data = url($file->uri, array('absolute' => TRUE));
              }
markosef’s picture

It is better when using multisite. :)

Jaggi’s picture

I preferred to do it this way as its much cleaner and does the same job:

elseif ($export_mode == 'remote') {
      $export_data = file_create_url($file->uri);
}

Also this is a bug as the url will always have public:// stream and the url method doesn't handle this type of url.

m4olivei’s picture

#4 worked for me, and IMO is the most correct way to do it. I'm attaching a patch against 7.x-3.0.

For those using the Drush command to export their nodes as I am, I also found that you need to use the --uri command line param to have the correct URL generated for the remote file export method, eg:

drush --uri=http://example.com node-export-export --file=my_node_export.txt --format=drupal --type=article
m4olivei’s picture

Status: Active » Needs review
Maxime Gilbert’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This works like a charm: must be released.

marko b’s picture

This seem to work, even on multisite, good job.

JMC’s picture

Patch #5 worked for me, thanks.

camp5456’s picture

#5 worked for me. Thanks!

  • danielb committed c36ef59 on 7.x-3.x authored by m4olivei
    Issue #2046431 by m4olivei: Public instead of files
    
danielb’s picture

Status: Reviewed & tested by the community » Closed (fixed)