Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

node.js - NodeJS Azure Function to copy blob across storage account

I have a private storage account with a container. When i upload a blob to the container, I trigger a 'BlobCreated' event with Event Grid, which is then picked up by a function.

The aim of the function is to copy the source blob to another 'backup' storage account.

I am using the new @azure/storage-blob & @azure/identity NodeJS packages.

const {BlobServiceClient} = require('@azure/storage-blob');
const {ManagedIdentityCredential} = require('@azure/identity');
question from:https://stackoverflow.com/questions/65875321/nodejs-azure-function-to-copy-blob-across-storage-account

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems to be an authentication problem, you can try to use StorageSharedKeyCredential to authenticate.

    const sourceCert = new StorageSharedKeyCredential(sourceAccountName,sourceAccountKey) 
    const sourceBlobServiceClient = new BlobServiceClient(
        `https://${sourceAccountName}.blob.core.windows.net`,
        sourceCert
    );

    const destinationCert = new StorageSharedKeyCredential(destinationAccountName,destinationAccountKey)
    const destBlobServiceClient = new BlobServiceClient(
        `https://${destinationAccountName}.blob.core.windows.net`,
        destinationCert
    );

    const sourceContainer = sourceBlobServiceClient.getContainerClient(containerName);
    const destContainer = destBlobServiceClient.getContainerClient(containerName);
    await destContainer.createIfNotExists();
    const sourceBlob = sourceContainer.getBlobClient(blobName);
    const destBlob = destContainer.getBlobClient(sourceBlob.name);
    const response = await destBlob.beginCopyFromURL(sourceBlob.url);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...