You are here

function flysystem_file_download in Flysystem 8

Same name and namespace in other branches
  1. 7 flysystem.module \flysystem_file_download()
  2. 3.x flysystem.module \flysystem_file_download()
  3. 2.0.x flysystem.module \flysystem_file_download()
  4. 3.0.x flysystem.module \flysystem_file_download()

Implements hook_file_download().

2 calls to flysystem_file_download()
ModuleFunctionsTest::testFlysystemFileDownloadFindsValidScheme in tests/src/Unit/ModuleFunctionsTest.php
Tests flysystem_file_download() handles valid schemes.
ModuleFunctionsTest::testFlysystemFileDownloadIgnoresInvalidScheme in tests/src/Unit/ModuleFunctionsTest.php
Tests flysystem_file_download() ignores invalid schemes.

File

./flysystem.module, line 25
Provides access to various filesystem backends using Flysystem.

Code

function flysystem_file_download($uri) {
  $schemes = Drupal::service('flysystem_factory')
    ->getSchemes();
  $scheme = Drupal::service('file_system')
    ->uriScheme($uri);
  if (!$scheme || !in_array($scheme, $schemes, TRUE)) {
    return;
  }
  return [
    'Content-Type' => Drupal::service('file.mime_type.guesser.extension')
      ->guess($uri),
    'Content-Length' => filesize($uri),
  ];
}