How to process a file using Azure Function

0 votes

I would like to process an input file and output it to some location for ex. FTP or Azure storage. I am trying to use Azure Function with SaasFile input/output. I am getting below error:

2016-07-14T00:44:53 Welcome, you are now connected to log-streaming service. 2016-07-14T00:45:00.580 Script for function 'HttpTriggerCSharp1' changed. Reloading. 2016-07-14T00:45:00.580 Compiling function script. 2016-07-14T00:45:00.721 run.csx(24,25): error CS0622: Can only use array initializer expressions to assign to array types. Try using a new expression instead. 2016-07-14T00:45:00.721 Compilation failed.

Here is my function signature:

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, string output, TraceWriter log)

Bindings:

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in"
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    },
    {
      "type": "apiHubFile",
      "name": "output",
      "path": "path/{file}",
      "connection": "ftp_FTP",
      "direction": "out"
    }
  ],
  "disabled": false
}

I think I am missing something in Run signature. I couldn't find it on Azure documentation.

I need help figure out how to process using FTP and Azure Storage. Thanks for your help.

Jun 18, 2018 in Azure by null_void
• 3,220 points
7,327 views

2 answers to this question.

+1 vote
Best answer

You don't really need a http trigger for this. Here is an example which watches a folder(input-cs) for new files in dropbox and copies the file to a folder (output-cs) in googledrive:

using System;

public static void Run(string input, out string output, TraceWriter log)
{
    output = input;
}

bindings:

{

 "bindings": [
    {
      "type": "apiHubFileTrigger",
      "name": "input",
      "direction": "in",
      "path": "input-cs/{name}",
      "connection": "dropbox_DROPBOX"
    },
    {
      "type": "apiHubFile",
      "name": "output",
      "direction": "out",
      "path": "output-cs/{name}",
      "connection": "googledrive_GOOGLEDRIVE"
    }
  ],
  "disabled": false
}


Hope it helps!

If you need to know more about Azure, then you should join Azure cloud certification course today.

Thank you!!

answered Jun 18, 2018 by club_seesharp
• 3,450 points

selected Jun 18, 2018 by null_void
+1 vote

Good news.. External File trigger is available for Azure functions.

If you want to process file in an external FTP folder, create a FTP connection first and then use it.

So your bindings array for FTP connection in function.json shown below.

{
  "bindings": [
    {
      "type": "apiHubFileTrigger",
      "name": "inputFile",
      "direction": "in",
      "path": "input-cs/{name}",
      "connection": "ftp_FTP"
    },
    {
      "type": "apiHubFile",
      "name": "$return",
      "direction": "out",
      "path": "output-cs/{name}",
      "connection": "ftp_FTP"
    }
  ],
  "disabled": false
}

In the above JSON,

path

Represents the path of the file to be processed. So in above case, azure function will be triggered when a file is added/modified in input-cs folder.

connection

Represents the External File connector name.

answered Jun 18, 2018 by cloudie_crank
• 1,610 points
Thank you :)

Related Questions In Azure

+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
2,237 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to create a deployment from a remote template file in Azure?

Hi@akhtar, You can create a deployment from a ...READ MORE

answered Nov 15, 2020 in Azure by MD
• 95,460 points
563 views
0 votes
2 answers

How can I download a .vhd image to my local machine from azure and upload the same to a different azure account?

From the Windows Azure Portal you can ...READ MORE

answered Aug 20, 2018 in Azure by Priyaj
• 58,020 points
14,008 views
0 votes
1 answer

How to add an App Settings to existing Azure Web Application using Azure Power Shell?

The example is for slot-specific settings, if ...READ MORE

answered Jun 13, 2018 in Azure by club_seesharp
• 3,450 points
1,439 views
0 votes
1 answer

How to identify a deadlock in SQL Azure?

Monitoring of SQL Azure is more limited ...READ MORE

answered Jun 19, 2018 in Azure by club_seesharp
• 3,450 points
2,653 views
+1 vote
1 answer

How to copy Azure SQL database to a local development server?

Actually, there are multiple ways to do ...READ MORE

answered Jul 9, 2018 in Azure by null_void
• 3,220 points
2,642 views
0 votes
1 answer

How to upload a file on to Azure Blob storage without writing a code?

You can find the below tools useful ...READ MORE

answered Apr 13, 2018 in Azure by club_seesharp
• 3,450 points
1,600 views
0 votes
1 answer

Azure Blob: How to open a file in browser without downloading it?

First, because I was using a byte[] the controller ...READ MORE

answered Jun 20, 2018 in Azure by club_seesharp
• 3,450 points
24,722 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP