generated from bitprj/Intro-To-Serverless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.3.1.js
50 lines (39 loc) · 1.89 KB
/
test.3.1.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const connectionString = process.env.storage_account_connection_string;
const containerName = process.env.container_name;
const { BlobServiceClient } = require("@azure/storage-blob");
const fs = require("fs")
const functions = require('./functions.js')
const args = require('minimist')(process.argv.slice(2))
const user = args['user'];
const repo = args['repo'];
async function main() {
try {
functions.checkSecret(connectionString, "connectionString")
functions.checkSecret(containerName, "containerName")
fs.readFile(`${__dirname}/testimage.jpg`, async function (err, content) {
try {
const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);
// Create a unique name for the container
console.error('\nCreating container...');
console.error('\t', containerName);
// Get a reference to a container
const containerClient = blobServiceClient.getContainerClient(containerName);
// Create the container
const blobName = 'bitcamptest.jpg';
// Get a block blob client
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
console.error('\nUploading to Azure storage as blob:\n\t', blobName);
// Upload data to the blob
const uploadBlobResponse = await blockBlobClient.upload(content, content.length);
} catch (e) {
console.error("Sorry! You haven't created your blob storage account yet. Check your secrets!")
await functions.throwError(`Error with creating blob storage account, check your secrets! Here is the error: ${e}`, user, repo)
process.exit(1)
}
})
}
catch (e) {
await functions.throwError(e, user, repo)
}
}
main();