Reputation: 63
I want to trigger the function app when a file is uploaded into the container and read the content in the file. I'm able to trigger the function app. But when i use Openread to read the content in the file i'm getting reference not found error. Below is the code which I have used to read the file and the binding.
#r "System.IO";
using System;
using System.Collections.Generic;
using System.IO;
using System.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Xml;
using Microsoft.Win32;
using System.Net;
using System.Linq;
public static void Run(Stream myBlob, string name, TraceWriter log, string
inputBlob)
{
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size:
{myBlob.Length} Bytes");
StreamReader reader = new StreamReader(inputBlob.OpenRead())
{
String oldContent = reader.ReadToEnd();
}
}
Bindings
{
"bindings": [{
"name": "myBlob",
"type": "blobTrigger",
"direction": "in",
"path": "sample/{name}",
"connection": "testforfunctionapp_STORAGE"
}, {
"type": "blob",
"name": "inputBlob",
"path": "sample/{name}",
"connection": "testforfunctionapp_STORAGE",
"direction": "in"
}
],
"disabled": false
}
Could anyone please help on this?
Thanks
Upvotes: 6
Views: 22418
Reputation: 24569
You could follow this document to create a blob trigger.
i'm getting reference not found error
In your case, the inputBlob
is a string type, you can't use inputBlob.OpenRead()
. And there is no need additional bind inputBlob
Please have a try to use the following code. It works correctly on my side.
#r "System.IO"
using System;
using System.Collections.Generic;
using System.IO;
public static void Run(Stream myBlob, string name, TraceWriter log)
{
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
StreamReader reader = new StreamReader(myBlob);
string oldContent = reader.ReadToEnd();
log.Info($"oldContent:{oldContent}");
}
Upvotes: 6
Reputation: 2513
I didn't see the GetblobReference, which could be the cause of the issue:
var blob = container.GetBlobReference("testblob.txt");
blob.UploadText(new String('x', 5000000));
var source = blob.OpenRead();
You can check the official doc for it here
I'd also recommend checking the example in this thread
Upvotes: 1