Skip to content

Commit

Permalink
Prevent ContentType assignation when dirs are created.
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeko committed Feb 13, 2019
1 parent 883b02c commit c824339
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/AwsS3Adapter.php
Expand Up @@ -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 {
Expand All @@ -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.
*
Expand Down Expand Up @@ -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'], '/');

Expand Down

0 comments on commit c824339

Please sign in to comment.