public function S3fsStream::stream_flush in S3 File System 4.0.x
Same name and namespace in other branches
- 8.3 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::stream_flush()
- 8.2 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::stream_flush()
Flushes the output.
This method is called in response to fflush() and when the stream is being closed while any un-flushed data has been written to it before. If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
Note, if not implemented, FALSE is assumed as the return value.
Return value
bool Should return TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.
Overrides PhpStreamWrapperInterface::stream_flush
See also
fflush()
http://php.net/manual/en/streamwrapper.stream-flush.php
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;
}