Skip to content

Commit

Permalink
[BUGFIX] Correctly set MIME type of .js and .css files
Browse files Browse the repository at this point in the history
Resolves: #85
  • Loading branch information
cweiske committed Oct 13, 2022
1 parent a7838aa commit 23f1f39
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Classes/S3Adapter/MultipartUploaderAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class MultipartUploaderAdapter extends AbstractS3Adapter
{
const MAX_RETRIES = 10;

protected static $mimeTypeMap = [
'css' => 'text/css',
'js' => 'text/javascript',
];

/**
* @param string $localFilePath File path and name on local storage
* @param string $targetFilePath File path and name on target S3 bucket
Expand All @@ -38,6 +43,15 @@ public function upload(string $localFilePath, string $targetFilePath, string $bu
$contentType = finfo_file($fileInfo, $localFilePath);
finfo_close($fileInfo);

if ($contentType == 'text/plain') {
// file's magic database often fails to detect plain text files
// we manually fix the mime type here.
$ext = pathinfo($targetFilePath, PATHINFO_EXTENSION);
if (isset(static::$mimeTypeMap[$ext])) {
$contentType = static::$mimeTypeMap[$ext];
}
}

$uploader = new MultipartUploader($this->s3Client, $localFilePath, [
'bucket' => $bucket,
'key' => $targetFilePath,
Expand Down

0 comments on commit 23f1f39

Please sign in to comment.