diff --git a/src/AwsS3Adapter.php b/src/AwsS3Adapter.php index e58c161..076ed36 100644 --- a/src/AwsS3Adapter.php +++ b/src/AwsS3Adapter.php @@ -580,16 +580,18 @@ protected function upload($path, $body, Config $config) $options = $this->getOptionsFromConfig($config); $acl = array_key_exists('ACL', $options) ? $options['ACL'] : 'private'; - if ( ! isset($options['ContentType'])) { - $options['ContentType'] = Util::guessMimeType($path, $body); - } + if (!$this->isOnlyDir($path)) { + if ( ! isset($options['ContentType'])) { + $options['ContentType'] = Util::guessMimeType($path, $body); + } - if ( ! isset($options['ContentLength'])) { - $options['ContentLength'] = is_resource($body) ? Util::getStreamSize($body) : Util::contentSize($body); - } + if ( ! isset($options['ContentLength'])) { + $options['ContentLength'] = is_resource($body) ? Util::getStreamSize($body) : Util::contentSize($body); + } - if ($options['ContentLength'] === null) { - unset($options['ContentLength']); + if ($options['ContentLength'] === null) { + unset($options['ContentLength']); + } } try { @@ -601,6 +603,17 @@ protected function upload($path, $body, Config $config) return $this->normalizeResponse($options, $path); } + /** + * Check if the path contains only directories + * + * @param string $path + * @return bool + */ + private function isOnlyDir($path) + { + return substr($path, -1) === '/'; + } + /** * Get options from the config. * @@ -657,7 +670,7 @@ protected function normalizeResponse(array $response, $path = null) $result['timestamp'] = strtotime($response['LastModified']); } - if (substr($result['path'], -1) === '/') { + if ($this->isOnlyDir($result['path'])) { $result['type'] = 'dir'; $result['path'] = rtrim($result['path'], '/');