Skip to content

Commit 8859a9a

Browse files
Add Content-Type to uploadBlobs function (#990)
1 parent fdcc0b1 commit 8859a9a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"liquidjs": "^9.16.1",
8484
"lodash": "^4.17.20",
8585
"lunr": "^2.3.9",
86+
"mime-types": "^2.1.27",
8687
"moment": "^2.29.1",
8788
"msal": "^1.4.1",
8889
"prismjs": "^1.22.0",

scripts.v2/utils.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const path = require("path");
33
const https = require("https");
44
const { BlobServiceClient } = require("@azure/storage-blob");
55
const blobStorageContainer = "content";
6+
const mime = require("mime-types");
67

78
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
89

@@ -116,7 +117,14 @@ async function downloadBlobs(blobStorageUrl, localMediaFolder) {
116117

117118
for await (const blob of blobs) {
118119
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
119-
await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}`);
120+
const extension = mime.extension(blob.properties.contentType);
121+
122+
if (extension != null) {
123+
await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}.${extension}`);
124+
}
125+
else {
126+
await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}`);
127+
}
120128
}
121129
}
122130

@@ -127,8 +135,15 @@ async function uploadBlobs(blobStorageUrl, localMediaFolder) {
127135

128136
for (const fileName of fileNames) {
129137
const blobName = path.basename(fileName).split(".")[0];
138+
const contentType = mime.lookup(path.extname(fileName));
139+
130140
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
131-
await blockBlobClient.uploadFile(fileName)
141+
142+
await blockBlobClient.uploadFile(fileName, {
143+
blobHTTPHeaders: {
144+
blobContentType: contentType
145+
}
146+
});
132147
}
133148
}
134149

@@ -150,4 +165,4 @@ module.exports = {
150165
uploadBlobs,
151166
deleteBlobs,
152167
getStorageSasTokenOrThrow
153-
};
168+
};

0 commit comments

Comments
 (0)