0

i have a bunch of VHD files stored on a private Server, which are accessible through a url.

I am trying upload these vhd files directly to my azure storage account using the azure javascript npm libraries. The vhds have to be uploaded as page-blobs. I tried using the method uploadPagesFromURL() of the pageblobClient but with no success. My code looks roughly like this:

 async function uploadVHD(accessToken, srcUrl) 
 {
     try {
         // Get credentials from accessToken
         const creds = new StorageSharedKeyCredential(storageAccount.name, storageAccount.key);
         // Get 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");
         // Get fileSize 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;
     }
 });
  • The url in `uploadPagesFromURL` is the Specific URL of the source blob. That means if it is public, url looks like `https://myaccount.blob.core.windows.net/mycontainer/myblob`, if it is not public, url looks like `https://myaccount.blob.core.windows.net/mycontainer/myblob?sas-token`. Do you want to upload a url that is not related to storage, for example https://i.stack.imgur.com/sc74e.png? – unknown Mar 19 '21 at 01:16
  • Hey @Pamela Peng The picture you attached, is blank when i view it but i am guessing i understood you correctly. Yes the url i want to use is independant from the storage, and uses basic authentication with username and password. – Reinhard Sanz Mar 19 '21 at 07:11

1 Answers1

0

It is not possible to upload the Page Blob with your URL directly. You need to read data from the url. Then upload using uploadPages method.

axios.get(URL, {
    responseType: 'arraybuffer'
  })
    .then((response) => {
        console.log(response.data)
        console.log(response.data.length)
        // upload page blob...
    }).catch((error) => {
      //handle error
    });

// uploadPages method
const uploadResponse = pageBlobClient.uploadPages(data, 0, dataLength);
unknown
  • 6,778
  • 1
  • 5
  • 14
  • Will this work for large files? The vhds that i am downloading can be really big. (>16GB) – Reinhard Sanz Mar 19 '21 at 09:25
  • I'm afraid it will take a long time and may return exceptions. We usually put large Blob with [API](https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob#remarks), you could refer to the [sample](https://stackoverflow.com/a/58741171/13308381). – unknown Mar 19 '21 at 09:42
  • I guess i just have to try it, timing "should" not be too much of an issue, i just set the timeout extremly high for now and see what happens. Thanks! – Reinhard Sanz Mar 19 '21 at 09:50