1
+ // Before you run the script, you need to
2
+ // 1. Install the azure-storage package: `npm install azure-storage`
3
+ // 2. Assign the storage connection string to the connectionString variable below
4
+
5
+ const azure = require ( 'azure-storage' ) ;
6
+
7
+ let connectionString = "DefaultEndpointsProtocol=https;AccountName=..." ;
8
+
9
+ function generateSasToken ( container , connectionString ) {
10
+ const blobName = "" ;
11
+ let blobService = azure . createBlobService ( connectionString ) ;
12
+
13
+ // Create a SAS token that expires in an hour
14
+ // Set start time to five minutes ago to avoid clock skew.
15
+ let startDate = new Date ( ) ;
16
+ startDate . setMinutes ( startDate . getMinutes ( ) - 5 ) ;
17
+ let expiryDate = new Date ( startDate ) ;
18
+ expiryDate . setHours ( startDate . getHours ( ) + 24 * 60 ) ; // 60 days expiration
19
+
20
+ permissions = azure . BlobUtilities . SharedAccessPermissions . READ +
21
+ azure . BlobUtilities . SharedAccessPermissions . WRITE +
22
+ azure . BlobUtilities . SharedAccessPermissions . DELETE +
23
+ azure . BlobUtilities . SharedAccessPermissions . LIST ;
24
+
25
+ let sharedAccessPolicy = {
26
+ AccessPolicy : {
27
+ Permissions : permissions ,
28
+ Start : startDate ,
29
+ Expiry : expiryDate
30
+ }
31
+ } ;
32
+
33
+ let sasToken = blobService . generateSharedAccessSignature (
34
+ container ,
35
+ blobName ,
36
+ sharedAccessPolicy
37
+ ) ;
38
+
39
+ return {
40
+ token : sasToken ,
41
+ uri : blobService . getUrl ( container , blobName , sasToken , true )
42
+ } ;
43
+ }
44
+
45
+ const container = "content" ;
46
+ let tokenObject = generateSasToken ( container , connectionString ) ;
47
+ let url = `${ tokenObject . uri } ?${ tokenObject . token } ` ;
48
+
49
+ console . log ( "SAS URL: " , url )
0 commit comments