Azure Blob Storage崩溃电子应用程序

时间:2018-01-28 02:05:55

标签: javascript node.js electron azure-storage azure-blob-storage

当我将电子应用中的图片发布到blob存储时,有时会有效,有时我会在终端上收到此错误:

enter image description here

当我第一次使用这个应用程序时,这个问题从未出现过,直到一周前。它没有对应用程序的这一部分进行任何更改。任何可能导致它的想法。

电子应用程序变白,开发工具断开连接。

以下是代码:



var azure = require('azure-storage');
var blobSvc = azure.createBlobService('*connection keys inside here*');

function createBlob() {
  blobSvc.createContainerIfNotExists('photos', {publicAccessLevel : 'blob'}, function(error, result, response){
    if(!error){
      console.log(response);
    }
  });
  console.log("creating image for student#: " + stud_id);
  blobSvc.createBlockBlobFromStream('photos', stud_id + '.jpg', toStream(imgData), imgData.size, function(error, result, response){
    if(!error){
      console.log("file upload: \n" + JSON.stringify(result) + " \n" + JSON.stringify(response));
      createPerson();
    }
    else if (error) {
      console.log("error: " + JSON.stringify(error));
    }
  });
}




1 个答案:

答案 0 :(得分:1)

在您的代码中,您实际上是立即调用createBlockBlobFromStream,可能没有创建容器。这可能会导致问题。

因此,您需要将它们放在createContainerIfNotExists函数的回调中:

blobSvc.createContainerIfNotExists('photos', {publicAccessLevel : 'blob'}, function(error, result, response) {
  if(!error) {
    console.log(response);

    console.log("creating image for student#: " + stud_id);
    blobSvc.createBlockBlobFromStream('photos', stud_id + '.jpg', toStream(imgData), imgData.size, function(error, result, response) {
      if(!error) {
        console.log("file upload: \n" + JSON.stringify(result) + " \n" + JSON.stringify(response));
        createPerson();

      } else {
        console.log("error: " + JSON.stringify(error));
      }
    });
  }
});