Skip to content

Commit

Permalink
Add Content-Type to uploadBlobs function (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomBonnerAtTFL authored Oct 21, 2020
1 parent 67f7044 commit 2477293
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"liquidjs": "^9.16.1",
"lodash": "^4.17.20",
"lunr": "^2.3.9",
"mime-types": "^2.1.27",
"moment": "^2.29.1",
"msal": "^1.4.1",
"prismjs": "^1.22.0",
Expand Down
21 changes: 18 additions & 3 deletions scripts.v2/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require("path");
const https = require("https");
const { BlobServiceClient } = require("@azure/storage-blob");
const blobStorageContainer = "content";
const mime = require("mime-types");

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

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

for await (const blob of blobs) {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}`);
const extension = mime.extension(blob.properties.contentType);

if (extension != null) {
await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}.${extension}`);
}
else {
await blockBlobClient.downloadToFile(`${localMediaFolder}/${blob.name}`);
}
}
}

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

for (const fileName of fileNames) {
const blobName = path.basename(fileName).split(".")[0];
const contentType = mime.lookup(path.extname(fileName));

const blockBlobClient = containerClient.getBlockBlobClient(blobName);
await blockBlobClient.uploadFile(fileName)

await blockBlobClient.uploadFile(fileName, {
blobHTTPHeaders: {
blobContentType: contentType
}
});
}
}

Expand All @@ -150,4 +165,4 @@ module.exports = {
uploadBlobs,
deleteBlobs,
getStorageSasTokenOrThrow
};
};

0 comments on commit 2477293

Please sign in to comment.