public function S3fsStream::stream_flush in S3 File System 8.3
Same name and namespace in other branches
- 8.2 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::stream_flush()
- 4.0.x src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::stream_flush()
Return value
bool
Overrides PhpStreamWrapperInterface::stream_flush
File
- src/
StreamWrapper/ S3fsStream.php, line 725
Class
- S3fsStream
- Defines a Drupal s3 (s3://) stream wrapper class.
Namespace
Drupal\s3fs\StreamWrapperCode
public function stream_flush() {
// phpcs:enable
// Prepare upload parameters.
$options = $this
->getOptions();
$params = $this
->getCommandParams($this
->getUri());
$mimeGuesser = \Drupal::service('file.mime_type.guesser');
if (method_exists($mimeGuesser, 'guessMimeType')) {
$contentType = $mimeGuesser
->guessMimeType($params['Key']);
}
else {
$contentType = $mimeGuesser
->guess($params['Key']);
}
$options[$this->protocol]['ContentType'] = $contentType;
if (!$this->uploadAsPrivate && StreamWrapperManager::getScheme($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'];
}
// Allow other modules to alter the upload params.
\Drupal::moduleHandler()
->alter('s3fs_upload_params', $options[$this->protocol]);
stream_context_set_option($this->context, $options);
if (parent::stream_flush()) {
$this
->writeUriToCache($this->uri);
return TRUE;
}
return FALSE;
}