当我将电子应用程序中的图片发布到Blob存储时,有时可以正常使用,而有时我在终端上收到此错误:

javascript - Azure Blob存储使电子应用程序崩溃-LMLPHP

当我第一次使用此应用程序时,直到一个星期前,这个问题才出现。发生时未对应用程序的此部分进行任何更改。关于可能导致它的任何想法。

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

这是代码:



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));
    }
  });
}

最佳答案

在您的代码中,您实际上可能立即调用了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));
      }
    });
  }
});

07-28 01:37
查看更多