GithubHelp home page GithubHelp logo

drupal_file_downloader's Introduction

drupal_file_downloader

Drupal module to download files from remote locations

Circle CI

Why?

When using hook_update_N() to deliver updates, it is sometimes necessary to fetch files from remote location and store them. This helper module allows to have different download providers as a source of such files.

Supported providers

  • FTP - COMPLETED
  • Amazon S3 - COMPLETED

Example FTP

// Set FTP provider configuration.
variable_set('drupal_file_downloader_ftp_host', 'your_ftp_hostname');
variable_set('drupal_file_downloader_ftp_root_path', 'your_common_storage_dir');
variable_set('drupal_file_downloader_ftp_username', 'your_username');
variable_set('drupal_file_downloader_ftp_password', 'your_password');

// This will download all files from all subdirectories of directory 
// `remote_dir` on the FTP server.
// So, if the path for a file was `/home/user/ftp_dir/dump/media_images/1.jpg`,
// `dump` is a `root_path`, `media_images` is a directory to pass to download()
// method and `1.jpg` is a filename.
// The return will have all downloaded files as array keyed by 'fid' for
// managed files or by real file paths for non-managed files.
$downloaded_files = Drupal\drupal_file_downloader\Downloader::download('FTP', 'remote_dir');

// Perform some operations with files.

// Cleanup downloaded files.
Drupal\drupal_file_downloader\Downloader::cleanup(downloaded_files);

Example S3

// This will download all files from all subdirectories of remote Amazon S3
// bucket directory 'remote_dir' into local directory 'public://remote_dir'
// as non-managed files and will print file download result.
// The return will have all downloaded files as array keyed by 'fid' for
// managed files or by real file paths for non-managed files.
$downloaded_files = Drupal\drupal_file_downloader\Downloader::download('S3', 'remote_dir', ['provider_config' => ['bucket' => 'mybucket.example.com']]);

// Perform some operations with files.

// Cleanup downloaded files.
Drupal\drupal_file_downloader\Downloader::cleanup(downloaded_files);

Installation

Depending on your provider, you may need to install additional modules.

FTP Provider

  1. Install xautoload module.
  2. Install 3rd party library php-ftp-client library into your libraries directory, so that FileClient.php file would be located at sites/all/libraries/php-ftp-client/src/FtpClient/FtpClient.php.
  3. Set default FTP configuration:
$conf['drupal_file_downloader_ftp_host'] = 'your_ftp_hostname';
$conf['drupal_file_downloader_ftp_username'] = 'your_username';
$conf['drupal_file_downloader_ftp_password'] = 'your_password';
$conf['drupal_file_downloader_ftp_root_path'] = 'your_common_storage_dir';

S3 Provider

  1. Install xautoload module.

  2. Install s3fs drupal module.

  3. Install AWS SDK PHP library - follow instructions on s3fs module's page.

  4. Set AWS access and secret key variables (add to your settings.php):

    • $conf['awssdk2_access_key'] = 'your_access_key_here';
    • $conf['awssdk2_secret_key'] = 'your_secret_key_here';
  5. Set AWS region variable (add to your settings.php):

    • $conf['s3fs_region'] = 'your_region';

drupal_file_downloader's People

Contributors

alexskrypnyk avatar

Watchers

 avatar  avatar

drupal_file_downloader's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.