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
With Azure Blob storage library v12, you can use BlobBaseClient.Exists()/BlobBaseClient.ExistsAsync()
Usage is something like below,
var blobServiceClient = new BlobServiceClient(_storageConnection);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(_containerName);
BlobClient blobClient = containerClient.GetBlobClient(blobName);
bool isExists = await blobClient.ExistsAsync(cancellationToken);
BlobBaseClient.Exists(CancellationToken) Method
BlobBaseClient.ExistsAsync(CancellationToken) Method
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"
}
Check if your Blob exists in the container, but then you will need to add the CloudBlobContainer as input parameter as well.
CloudBlockBlob existingBlob = container.GetBlockBlobReference(blobName);
And check if it exists using
await existingBlob.ExistsAsync()
Java version for the same ( using the new v12 SDK )
This uses the Shared Key Credential authorization, which is the account access key.
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);
BlobServiceClient storageClient = new BlobServiceClientBuilder().credential(credential)
.endpoint(endpoint).buildClient();
BlobContainerClient container = storageClient.getBlobContainerClient(containerName)
if ( container.exists() ) {
// perform operation when container exists
}