-
Notifications
You must be signed in to change notification settings - Fork 48
/
copy-blob-put-from-url.js
57 lines (45 loc) · 1.82 KB
/
copy-blob-put-from-url.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
51
52
53
54
55
56
57
// Azure Storage dependency
const {
BlobServiceClient,
BlockBlobClient
} = require('@azure/storage-blob');
// Azure authentication for credential dependency
const { DefaultAzureCredential } = require('@azure/identity');
// For development environment - include environment variables from .env
require("dotenv").config();
// TODO: Replace with your actual storage account name
const accountName = "<storage-account-name>";
async function main() {
// create service client from DefaultAzureCredential
const blobServiceClient = new BlobServiceClient(
`https://${accountName}.blob.core.windows.net`,
new DefaultAzureCredential()
);
const sourceBlob = blobServiceClient
.getContainerClient("source-container")
.getBlockBlobClient("sample-blob.txt");
const destinationBlob = blobServiceClient
.getContainerClient("destination-container")
.getBlockBlobClient("sample-blob-copy.txt");
copyFromSourceInAzure(sourceBlob, destinationBlob);
const sourceURL = "source-url";
const destBlob = blobServiceClient
.getContainerClient("sample-container")
.getBlockBlobClient("sample-blob-copy.txt");
copyFromExternalSource(sourceURL, destBlob);
}
// <Snippet_copy_from_azure_put_blob_from_url>
async function copyFromSourceInAzure(sourceBlob, destinationBlob) {
// Get the source blob URL and create the destination blob
await destinationBlob.syncUploadFromURL(sourceBlob.url);
}
// </Snippet_copy_from_azure_put_blob_from_url>
// <Snippet_copy_from_external_source_put_blob_from_url>
async function copyFromExternalSource(sourceUrl, destinationBlob) {
// Create the destination blob from the source URL
await destinationBlob.syncUploadFromURL(sourceUrl);
}
// </Snippet_copy_from_external_source_put_blob_from_url>
main()
.then(() => console.log('done'))
.catch((ex) => console.log(ex.message));