Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create an azure blob trigger to copy the file uploaded to the azure blob to the on premise file system. Can anyone please provide the steps for the same?

What I have tried:

I created a blob trigger and bound its output parameter to external file(preview) and selected the File System API. It asks for Display name, root folder, username and password. What goes here and how to connect azure to my machine's file system?


This is my function.json file.

{
  "bindings": [
    {
      "name": "myBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "input/{name}",
      "connection": "connection_Name"
    },
    {
      "type": "apiHubFile",
      "name": "outputFile",
      "path": "outout/{name}",
      "connection": "file_system_connection_name",
      "direction": "out",
      "typeProperties": {
        "host": "HostName",
        "userid": "userid",
        "password": "userpassword",
        "gatewayName": "gatewayName"
      }
    }
  ],
  "disabled": false
}


This is my  run.csx  file.
public static void Run(Stream myBlob, string name, TraceWriter log,Stream outputFile)
{
        myBlob.CopyTo(outputFile);
}
Posted
Updated 24-Jul-23 2:31am
v2
Comments
Graeme_Grant 21-Aug-17 7:32am    
What source code? We can't see your screen from here. Please press the "Improve question" widget and update your question. If you do not know how, please read this: How to Improve my question - Code Project FAQ[^]
Graeme_Grant 21-Aug-17 8:26am    
I see that you updated the question, but did you actually click on the links that I provided? They are explaining what you are asking about...

To quote the last link:

** Create the container
In your function, click Integrate, expand Documentation, and copy both Account name and Account key. You use these credentials to connect to the storage account. If you have already connected your storage account, skip to step 4.
nilvish07 22-Aug-17 3:13am    
Yes I checked the link and that is already done. I have a blob trigger, a storage account. Now, what I want to do is on run of the blob trigger I need to copy the file in the storage container to a local folder of my computer

This search: download file from azure blob storage - Google[^] found this answer for you: Upload and Download files from Azure Storage – WebApps[^] - a step-by-step-guide through the complete process including screenshots and sample source code!

UPDATE: Blob triggers... This search: how to create a azure blob trigger function - Google Search[^] found this step-by-step guide: Create a function in Azure triggered by Blob storage | Microsoft Docs[^]

Research using Google search is the key! Try, it, it is not hard...
 
Share this answer
 
v2
Comments
nilvish07 21-Aug-17 7:46am    
I need to create an azure blob trigger function and bind its output parameter to external file which automatically copies the file to on premise file system when the blob is uploaded to the blob.
Graeme_Grant 21-Aug-17 7:54am    
updated solution
nilvish07 21-Aug-17 8:26am    
I have created the blob trigger but now I need to bind its output parameter to external "file system connection" to copy the file in the blob to my machine's local folder.
Graeme_Grant 21-Aug-17 8:33am    
You can't bind a local machine to an Azure Blob service. You should be able to push notifications from an Azure service to a webserver endpoint.
nilvish07 21-Aug-17 8:46am    
But with a data factory, we can copy a file from azure blob to local folder using Microsoft data management gateway and logic apps using on-premise data gateway. Is there any component which may allow to connect to the on premise machine?
There must be some way to connect as they have provided the facility for the same .
You can directly use ShareGate or Gs Richcopy 360 to files from azure blob to on-premise or from on-premise to azure blob ,but on the other hand you can use the following steps using c#:
-Create an Azure Function App project in Visual Studio.
-Add a new Function to the project with an Azure Blob Trigger.
-Install the Azure.Storage.Blobs NuGet package to your project.
-Add the following code to the Function:
C#
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using Azure.Storage.Blobs;

public static void Run(
    [BlobTrigger("container-name/{name}", Connection = "AzureWebJobsStorage")] BlobClient blobClient,
    string name, ILogger log)
{
    log.LogInformation($"C# Blob trigger function processed blob\n Name:{name} \n URI:{blobClient.Uri}");

    // Replace the file path with the path to the on-premise file system
    string filePath = @"C:\path\to\destination\file";

    // Download the blob to the file system
    blobClient.DownloadTo(filePath);
}


-Replace the "container-name" placeholder in the BlobTrigger attribute with the name of the Azure Blob Storage container you want to monitor.
-Replace the file path in the filePath variable with the path to the destination file on the on-premise file system.
-Deploy the Function App to Azure and configure the connection string for AzureWebJobsStorage in the Application Settings section of the Function App.

When a new blob is added to the specified container, the Azure Blob Trigger will fire the function and download the blob to the specified file path on the on-premise file system.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900