Check if file exists on blob storage with Azure functions

前端 未结 4 1237
走了就别回头了
走了就别回头了 2021-01-25 01:28

Based on https://ppolyzos.com/2016/12/30/resize-images-using-azure-functions/ I have the following C# code to resize an image using Azure Functions.

#r \"Microso         


        
4条回答
  •  面向向阳花
    2021-01-25 02:19

    Since you are using CloudBlockBlob type to bind outputBlob. You could check whether this blob exist or not using following code.

    if (outputBlob.Exists())
    {
        log.Info($"520x245-{blobname}.{blobextension} is already exist");  
    }
    else
    {
        log.Info($"520x245-{blobname}.{blobextension} is not exist");  
        //do the resize and upload the resized image to blob  
    }
    

    Currently, Azure Function doesn't allow us to use CloudBlockBlob in output blob binding. A workaround is change the direction to "inout" in function.json. After that, we can use CloudBlockBlob in output blob binding.

    {
      "type": "blob",
      "name": "outputBlob",
      "path": "mycontainer/520x245-{blobname}.{blobextension}",
      "connection": "connectionname",
      "direction": "inout"
    }
    

提交回复
热议问题