Add support for remote file systems for http downloaded data

Created on 30 March 2023, over 1 year ago

Problem/Motivation

In πŸ“Œ Missing temporary files in load balanced environments Fixed a service was added to handle Feeds files that are in progress of being imported. Http downloaded sources files are saved in either private://feeds/in_progress/x or public://feeds/in_progress/x.

In the service the function \Drupal\Core\File\FileSystemInterface::realpath() is used to figure out the directory to save he downloaded file to. This works fine on local file systems, but it causes issues on remote file systems like s3fs.

Steps to reproduce

TBD.

Proposed resolution

From #2912130-136: Missing temporary files in load balanced environments β†’ :

In FeedsFileSystemBase::tempnam(), instead of writing a temporary file with tempnam, I wrote a file w/ \Drupal::service('file.repository')->writeData(). This method should support local and remote stream wrappers. Then I got additional error information that the getAsync call in HttpFetcher::get() appears to open a file with "w+" permissions by default which s3 (and perhaps other remote stream wrappers) do not seem to allow: https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-stream-wra...

You can upload larger files by streaming data using fopen() and a β€œw”, β€œx”, or β€œa” stream access mode. The Amazon S3 stream wrapper does not support simultaneous read and write streams (e.g. β€œr+”, β€œw+”, etc). This is because the HTTP protocol doesn’t allow simultaneous reading and writing.

First opening the stream through GuzzleHttp\Psr7\Utils::tryFopen() with "w" mode and passing that filestream as the sink to getAsync worked perfectly. Not sure if other use cases require "w+"

Remaining tasks

  • Figure out a way to add test coverage for remote file systems.
  • Guzzle uses "w+" mode when fetching a file (write + read). Find out what the drawbacks are when "w" would be used instead.
  • Test the fix.
  • Review
  • Commit

User interface changes

TBD.

API changes

TBD.

Data model changes

TBD.

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands megachriz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024