.netazure-functionsazure-blob-storagesftpazure-blob-trigger

Azure Function fires twice with SFTP when files uploaded


I have a BlobTrigger Azure Function which works with SFTP Connection via Webhook Event in Container.

So my problem is when I upload files with SFTP Connection it fires my Azure Function twice. (via SFTP Clients(WinSCP, FileZilla etc.) or even with Windows Powershell directly it fires 2 times with two different IDs. )

But when I upload(without SFTP) directly to Storage Account\Container it fires only once as it must be.

How function monitor looks like when I upload my file via SFTP enter image description here

Logs

enter image description here

My Azure Function enter image description here

Tried to handle this with changing extension values in host.json such as maxConcurrent maxProcessor (1 most of the time..) none of it worked unfortunately. I've checked but there is only one slot, Sessions is not allowed etc.

My webhook event in Storage Account\Container

enter image description here


Solution

  • I found the issue and hopefully it can help someone else in the future;

    When we upload a blob directly from the Azure portal, it would only create a single "PutBlob" event, when you use sftp protocol (no matter what software it is), it would create 2 events (sftpcreate and sftpcommit) right after the sftpconnect event. Azure Blob Storage as Event Grid source - Azure Event Grid | Microsoft Learn.

    Based on the official documentation, SFTP uploads will generate 2 events. One SftpCreate for an initial empty blob created when opening the file and one SftpCommit when the file contents are written. If you want to ensure that the Microsoft.Storage.BlobCreated event is triggered only when a Block Blob is completely committed, filter the event for the SftpCommit REST API call.

    It meets my expectations