You are here

public function S3fsStreamWrapper::stream_flush in S3 File System 7.3

Same name and namespace in other branches
  1. 7 S3fsStreamWrapper.inc \S3fsStreamWrapper::stream_flush()
  2. 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::stream_flush()

Support for fflush(). Flush current cached stream data to a file in S3.

Return value

bool TRUE if data was successfully stored in S3.

Overrides StreamWrapperInterface::stream_flush

See also

http://php.net/manual/en/streamwrapper.stream-flush.php

File

./S3fsStreamWrapper.inc, line 658
Drupal stream wrapper implementation for S3 File System.

Class

S3fsStreamWrapper
The stream wrapper class.

Code

public function stream_flush() {

  // Prepare upload parameters.
  $options = $this
    ->getOptions();
  $options[$this->protocol]['ContentType'] = $this
    ->getMimeType($this->uri);

  // All non-private files uploaded to S3 must be set to public-read, or users' browsers
  // will get PermissionDenied errors, and torrent URLs won't work. The one exception to
  // this is when all content is being routed through an edge service and access via S3
  // should be blocked.
  if (!empty($this->config['use_cname']) && !empty($this->config['domain']) && !empty($this->config['domain_s3_private'])) {
    $options[$this->protocol]['ACL'] = 'private';
  }
  elseif (file_uri_scheme($this->uri) != 'private') {

    // All non-private files uploaded to S3 must be set to public-read, or users' browsers
    // will get PermissionDenied errors, and torrent URLs won't work.
    $options[$this->protocol]['ACL'] = 'public-read';
  }

  // Set the Cache-Control header, if the user specified one.
  if (!empty($this->config['cache_control_header'])) {
    $options[$this->protocol]['CacheControl'] = $this->config['cache_control_header'];
  }
  if (!empty($this->config['encryption'])) {
    $options[$this->protocol]['ServerSideEncryption'] = $this->config['encryption'];
  }

  // Legacy support: set bucket and key values that were present with
  // AWS SDK v2. Used by AdvAgg module with hook_s3fs_upload_params_alter().
  $options[$this->protocol]['Bucket'] = $this->config['bucket'];
  $convertedPath = $this
    ->convertUriToKeyedPath($this->uri, FALSE);
  $options[$this->protocol]['Key'] = file_uri_target($convertedPath);

  // Allow other modules to alter the upload params.
  drupal_alter('s3fs_upload_params', $options[$this->protocol]);

  // Legacy support: unset bucket and key values. Retaining them will
  // cause conflicts when saving AdvAgg's aggregated css/js files.
  unset($options[$this->protocol]['Bucket']);
  unset($options[$this->protocol]['Key']);
  stream_context_set_option($this->context, $options);
  if (parent::stream_flush()) {
    $this
      ->writeUriToCache($this->uri);
    return TRUE;
  }
  else {
    return FALSE;
  }
}