Skip to content

Commit aff735f

Browse files
committed
adds logic to upload compressed files with right mime type and right content encoding
1 parent d72b221 commit aff735f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/upload.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function uploadFile(aws, bucketName, filePath, fileKey, headers, sse) {
6262
Bucket: bucketName,
6363
Key: fileKey,
6464
Body: fileBuffer,
65-
ContentType: mime.lookup(filePath)
65+
...getMimeTypeAndContentEncoding(filePath)
6666
};
6767

6868
if (sse) {
@@ -180,4 +180,24 @@ function groupFilesByOrder(files, orderSpec) {
180180
return [unmatchedFiles].concat(matchedFiles);
181181
}
182182

183+
const ContentEncodingMap = {
184+
gz: 'gzip',
185+
br: 'br'
186+
};
187+
188+
function getMimeTypeAndContentEncoding(filePath) {
189+
const match = /(.+\..+)\.(gz|br)$/.exec(filePath);
190+
191+
if (match) {
192+
const [fullMatch, strippedFilePath, encodingFileEnding] = match;
193+
194+
return {
195+
ContentType: mime.lookup(strippedFilePath),
196+
ContentEncoding: ContentEncodingMap[encodingFileEnding]
197+
};
198+
}
199+
200+
return { ContentType: mime.lookup(filePath) };
201+
}
202+
183203
module.exports = uploadDirectory;

0 commit comments

Comments
 (0)