/
backupAzure.js
36 lines (33 loc) · 1.06 KB
/
backupAzure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const {
BlobServiceClient,
StorageSharedKeyCredential
} = require('@azure/storage-blob')
module.exports = async function (blobName, content) {
// Enter your storage account name and shared key
const {
account,
accountKey,
containerName
} = require('./config/config.js').azure
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(
account,
accountKey
)
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
)
const containerClient = blobServiceClient.getContainerClient(containerName)
// const blobName = `${name}-${new Date().getTime()}`
const blockBlobClient = containerClient.getBlockBlobClient(blobName)
const uploadBlobResponse = await blockBlobClient.upload(
content,
content.length
)
console.log(
`Upload block blob ${blobName} successfully`,
uploadBlobResponse.requestId
)
}