Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Do I Output to BlobStorage Using Binding Syntax? #201

Closed
keithdhodo opened this issue Aug 9, 2017 · 4 comments
Closed

How Do I Output to BlobStorage Using Binding Syntax? #201

keithdhodo opened this issue Aug 9, 2017 · 4 comments

Comments

@keithdhodo
Copy link

keithdhodo commented Aug 9, 2017

I have tried using the following two syntaxes to bind to BlobStorage and neither are working, though they did in the older style using function.json:

[Blob("Merging/{QuickFindSBTopicTrigger}.txt", Connection = "AzureWebJobsStorage")]IBinder binder
and
IBinder binder

This is the code that uses it:

using (var outputBlob = binder.Bind<TextWriter>(
                new BlobAttribute(blobPath, FileAccess.Write)))
            {
                outputBlob.WriteLine($"Number to Union From: {string.Join(",", myQueueItem.NumberToUnionFrom)}");
                outputBlob.WriteLine($"Number to Union To: {string.Join(",", myQueueItem.NumberToUnionTo)}");
                outputBlob.WriteLine($"Output of Merge: {string.Join(",", myQueueItem.Output)}");
                outputBlob.WriteLine();
                outputBlob.WriteLine($"Runtime: {performance.Runtime.ToString()}");

                // create Sha512 Hash
                var sha = new SHA512CryptoServiceProvider();
                // This is one implementation of the abstract class SHA512.
                var result = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(blobPath + myQueueItem.NumberToUnionFrom + myQueueItem.NumberToUnionTo + myQueueItem.Output));
                outputBlob.WriteLine($"Hash of Inputs, Output and Runtime: {BitConverter.ToString(result).Replace("-", "")}");
            }


I just can't make either one write to BlobStorage.

Thoughts?

@lindydonna
Copy link
Contributor

Here's documentation on how to use imperative bindings in Azure Functions: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#binding-at-runtime-via-imperative-bindings

@keithdhodo
Copy link
Author

keithdhodo commented Aug 11, 2017

Thanks @lindydonna! This bit solved my issues:

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.Bindings.Runtime;

public static async Task Run(string input, Binder binder)
{
    var attributes = new Attribute[]
    {    
        new BlobAttribute("samples-output/path"),
        new StorageAccountAttribute("MyStorageAccount")
    };

    using (var writer = await binder.BindAsync<TextWriter>(attributes))
    {
        writer.Write("Hello World!");
    }
}

Marking this issue as closed.

@tamsps
Copy link

tamsps commented Oct 24, 2017

@ssfcultra Where to write these code lines? in .csx file (like run.csx) or inside of an Azure Function? Thanks

@tamsps
Copy link

tamsps commented Oct 24, 2017

@ssfcultra Also, I have an Azure Function
[FunctionName("FunctionServiceBus")] public static void Run([ServiceBusTrigger("queue1", AccessRights.Manage, Connection = "AZServiceBusConn")]string myQueueItem, TraceWriter log) { log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}"); }

How can I load queue1 (Service Bus Queue Name) and AZServiceBusConn (Service Bus connection string) at initialize (dynamic at run time). After these data were loaded then I let launch Azure Function trigger with new data. Many thanks

@ghost ghost locked as resolved and limited conversation to collaborators Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants