I have a collection of VHD files stored on a secure server, accessible via URL links.
My goal is to transfer these VHD files directly to my Azure storage account using the Azure JavaScript npm libraries. The VHDs must be uploaded as page-blobs, but I encountered issues when attempting to use the uploadPagesFromURL() method of the pageBlobClient. Here is a simplified version of the code I tried:
async function uploadVHD(accessToken, srcUrl)
{
try {
// Obtain credentials from access token
const creds = new StorageSharedKeyCredential(storageAccount.name, storageAccount.key);
// Acquire blobServiceClient
const blobServiceClient = new BlobServiceClient(`https://${storageAccount.name}.blob.core.windows.net`, creds);
// Create Container
const containerClient = blobServiceClient.getContainerClient("vhd-images");
await containerClient.createIfNotExists();
const src = srcUrl.replace('https://', 'https://username:password@');
// Upload to blob storage
const pageBlobClient = containerClient.getPageBlobClient("Test.vhd");
// Retrieve file size of VHD
const fileSize = (await axiosRequest(src, { method: "HEAD" })).headers["content-length"];
const uploadResponse = await pageBlobClient.uploadPagesFromURL(src, 0, 0, fileSize);
return uploadResponse;
} catch (error) {
return error;
}
});