You are here

protected function File::getContent in Feeds 8.3

Attempts to download the file at the given url.

Parameters

string $url: The URL to download a file from.

Return value

string The file contents.

Throws

\Drupal\feeds\Exception\TargetValidationException In case the file could not be downloaded.

1 call to File::getContent()
File::getFile in src/Feeds/Target/File.php
Returns a file id given a url.

File

src/Feeds/Target/File.php, line 266

Class

File
Defines a file field mapper.

Namespace

Drupal\feeds\Feeds\Target

Code

protected function getContent($url) {
  $response = $this->client
    ->request('GET', $url);
  if ($response
    ->getStatusCode() >= 400) {
    $args = [
      '%url' => $url,
      '@code' => $response
        ->getStatusCode(),
    ];
    throw new TargetValidationException($this
      ->t('Download of %url failed with code @code.', $args));
  }
  return (string) $response
    ->getBody();
}