Search code examples
javascriptazureazure-storageazure-blob-storageazure-queues

how to insert to queue inside a queue trigger in a azure javascript function


i am implementing a queue trigger. what happen there is i receive url of pdf through the queue and i convert that pdf to png and i upload that png to azure blog storage. i want to add this new url of azure blob to a new queue. of course i can do this with azure storage SDK. instaed i want to use bindings. this is what i have done so far

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
}

code where i upload the png azure blob service and add the url to queue

 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")

 });

but it seems like it does not add the url to the queue. what am i doing wrong here


Solution

  • You should inform the runtime that your code has finished by calling context.done() from inside the callback of the createBlockBlobFromLocalFile function:

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