I am using remote files in my migration script. I store them like this:

<?php

$request = drupal_http_request($uri);

if ($request->code == 200) {

  $file = new stdClass();
  $file->fid = NULL;
  $file->uri = $uri;
  $file->filename = drupal_basename($uri);
  $file->filemime = file_get_mimetype($file->uri);

  $file = file_save($file);
}

?>

But the migration fails for a lot of files. I get error messages like this:

filesize(): stat failed for http://localhost/test.jpg File /includes/file.inc, line 570

Am I doing something wrong or is this a bug?

Comments

luksak’s picture

Issue summary: View changes

Typo

luksak’s picture

Issue summary: View changes

Syntax highlighting

luksak’s picture

Issue summary: View changes

Deleting code

luksak’s picture

Issue summary: View changes

typo

bunnicula’s picture

Issue summary: View changes

Did you ever figure this out? I'm getting the same error.

luksak’s picture

No, I don't think so...

bunnicula’s picture

I tried using the same syntax as was used in the form_submit and this seems to work. The error still occurs but the file object is created anyway.

  try {
    $file = remote_stream_wrapper_file_load_by_uri($uri);
    if (!$file) {
      $file = remote_stream_wrapper_file_create_by_uri($uri);
      file_save($file);
    }
  }
  catch (Exception $e) {
    form_set_error('url', $e->getMessage());
    return;
  }
duaelfr’s picture

I can confirm this issue.
file_save() always calls filesize() that only works on local files.

That module might rewrite the file_save function to bypass the filesize call or write its own as shown here.

twistor’s picture

Category: Bug report » Support request
Status: Active » Fixed

@Lukas von Blarer, yes you're doing something wrong :). filesize() works fine on stream wrappers. The only time this would fail is if the URL of the file isn't available.

For instance, http://localhost/test.jpg is probably not a valid, downloadable file.

Status: Fixed » Closed (fixed)

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