如何在azure javascript函数中插入队列内的队列触发器

时间:2018-01-31 13:07:41

标签: javascript azure azure-storage azure-blob-storage azure-queues

我正在实施队列触发器。发生了什么事情我通过队列收到pdf的网址,我将该pdf转换为png,然后我将该png上传到azure博客存储。我想将这个azure blob的新url添加到新队列中。当然我可以用azure存储SDK做到这一点。 instaed我想使用绑定。这就是我到目前为止所做的事情

function.json

{
  "bindings": [{
      "name": "pdffaxqueue",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "pdffaxqueue",
      "connection": "AzureWebJobsStorage"
  },
  {
    "type": "queue",
    "direction": "out",
    "name": "myQueueItemii",
    "queueName": "qsendtogettext",
    "connection": "STORAGEConnectionString"
  }],
  "disabled": false
}

代码,我上传png azure blob服务并将url添加到队列

 blobService.createBlockBlobFromLocalFile(CONTAINER_NAME, BLOCK_BLOB_NAME, './' + FileName, function(errorerror) {
     if (error) {
         context.res = {
             status: 400,
             headers: {
                 'Content-Type': 'application/json'
             },
             body: {
                 '__error': error
             }
         };
         context.done();
     }
     //removing the image after uploding to blob storage
     fs.unlinkSync('./' + FileName);


     context.log(context.bindings)
     context.bindings.myQueueItemii = [blobService.getUrl(CONTAINER_NAME, BLOCK_BLOB_NAME)];
     context.log("added to the q")

 });

但似乎它没有将url添加到队列中。我在这做错了什么

1 个答案:

答案 0 :(得分:0)

您应该通过从context.done()函数的回调中调用createBlockBlobFromLocalFile来告知运行时代码已完成:

blobService.createBlockBlobFromLocalFile(CONTAINER_NAME, BLOCK_BLOB_NAME, './' + FileName, function(errorerror) {

     // ...

     context.log(context.bindings)
     context.bindings.myQueueItemii = [blobService.getUrl(CONTAINER_NAME, BLOCK_BLOB_NAME)];
     context.log("added to the q")

     // Add this line here
     context.done()
});