Questions about download files from Azure Blob, need to make sure it finishes

My application is here I want to download a couple of files(data) from blob, and I want to make sure the actual files are already at local/virtual machine. Then I will continue to process those data by calling a exe file through execSync().

But the problem is every time the starting to down blobs, the code never waits the download finishes, so the following exe will cause error. I checked in some detail. When it starts downloading, the files appears at local machines, but the size is 0 bytes. Then the exe causes error. After I click the error, the blob truly finished downloading, the files size is not 0 any more. I’ve used await in my code, but it didn’t help.

Anyone have a insight??

const blobService = storage.createBlobService(blobStorageAccount, blobAccessKey); // Download blob to local files async function downloadBlobToLocal(containerName, blobName, localFileName){ return new Promise((resolve, reject) => { blobService.getBlobToLocalFile(containerName, blobName, localFileName, (err, result, response) => { if (err) { reject(err); } else { resolve({ message: `Blob downloaded locally "${result}"`, text: response }); } }); }); } async function listAndDownloadBlobs(containerName, prefix){ return new Promise((resolve, reject) => { blobService.listBlobsSegmentedWithPrefix(containerName, prefix, undefined, (err, data) => { // Loop through the directory and download to local folder data.entries.forEach(datafile =>{ let localFileName = path.resolve('./../', datafile.name); downloadBlobToLocal(containerName, datafile.name, localFileName); console.log(localFileName); }); if (err) { reject(err); } else { resolve({ message: `${data.entries.length} blobs in '${containerName}'`, blobs: data.entries }); } }); }); } const downloadBlob = async()=>{ // Download capture files var prefix_uuid = uuid; await listAndDownloadBlobs(containerName, prefix_uuid); } async function runfile(){ var file2Run1 = 'ReProcessTest.exe'; // Run reprocess try{ execSync(file2Run1); console.log('reprocess done'); } catch(error){ // Notify the sever that re-process is failed for reason $error. Re-run the matlab automation another time console.log(error); } } downloadBlob() .then(() => runfile()); 

submitted by /u/zachery2006
[link] [comments]

Leave a Reply