简体   繁体   English

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

[英]Azure Blob Storage crashes electron app

When I am posting a picture from my electron app to blob storage, sometimes it works, and other times I get this error on my terminal: 当我将电子应用程序中的图片发布到Blob存储时,有时可以正常使用,而有时我在终端上收到此错误:

在此处输入图片说明

When I was first working on this app, this problem never showed up, until a week ago. 当我第一次使用此应用程序时,直到一个星期前,这个问题才出现。 It occurred without making any changes to this part of the app. 发生时未对应用程序的此部分进行任何更改。 Any idea on what could cause it. 关于可能导致它的任何想法。

The electron app goes white, and the dev tools are disconnected. 电子应用程序变白,开发工具断开连接。

Here is the code: 这是代码:

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

In your code, you actually call the createBlockBlobFromStream immediately, probably without container having created. 在您的代码中,实际上可能立即调用了createBlockBlobFromStream ,可能没有创建容器。 This may cause the problem. 这可能会导致问题。

So, you would need to put them within the callback of the createContainerIfNotExists function: 因此,您需要将它们放在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));
      }
    });
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM