Skip to content

Commit

Permalink
fix mime type for S3
Browse files Browse the repository at this point in the history
  • Loading branch information
kringkaste committed Mar 1, 2021
1 parent fd59f4c commit e8ad2ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Craft AWS Plugin Changelog

## Unreleased
## 1.0.0-beta.2 - 2020-03-01

### Added
- Console command to generate thumbs without job/queues
- Config option for queue name for all mass updates (e.g. thumbs generating)

### Fixed
- If resourceRevision was a clousure, an error occured
- Fix AssetManager by adding S3 functions as trait
- Fix cached path of thumbnails
- Fix SVG mime type for older Craft CMS versions

## 1.0.0-beta.1 - 2019-04-06

### Added
- Initial release
26 changes: 23 additions & 3 deletions src/components/S3AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function hash($path)
public function getPublishedUrl($sourcePath, bool $publish = false, $filePath = null)
{
if ($publish === true) {
list(, $url) = $this->publish($sourcePath);
[, $url] = $this->publish($sourcePath);
} else {
$url = parent::getPublishedUrl($sourcePath);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ protected function publishFile($src): array
$dstFile = $dstDir . '/' . $fileName;

if (!$this->isPublished($dstFile)) {
$this->uploadFile($this->bucket, $dstFile, $src, FileHelper::getMimeType($src));
$this->uploadFile($this->bucket, $dstFile, $src, $this->_getMimetype($src));
}

return [$dstFile, $this->baseUrl . "/$dir/$fileName"];
Expand Down Expand Up @@ -224,7 +224,7 @@ protected function uploadDirectory($src, $dst, $options)
}

if (is_file($from)) {
$this->uploadFile($this->bucket, $to, $from, FileHelper::getMimeType($from));
$this->uploadFile($this->bucket, $to, $from, $this->_getMimetype($from));
} else if (!isset($options['recursive']) || $options['recursive']) {
$this->uploadDirectory($from, $to, $options);
}
Expand All @@ -234,4 +234,24 @@ protected function uploadDirectory($src, $dst, $options)
}
closedir($handle);
}

/**
* Get mime type and fix bugs.
*
* @param string $src The file path.
*
* @return string The mime type.
* @throws InvalidConfigException
*/
private function _getMimetype($src)
{
$mimeType = FileHelper::getMimeType($src);

// Handle invalid SVG mime type reported by PHP (https://bugs.php.net/bug.php?id=79045)
if ($mimeType === 'image/svg') {
$mimeType = 'image/svg+xml';
}

return (string)$mimeType;
}
}

0 comments on commit e8ad2ca

Please sign in to comment.