0
votes

I am creating an Azure function using Blob trigger, and when I publish this function to the portal and run the function.json, I am getting this error, what does this mean? I am not able to understand this error:

[Information] Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=eb4c27bd-7789-4988-9af8-83f2751c53d5) [Error] Executed 'Function1' (Failed, Id=eb4c27bd-7789-4988-9af8-83f2751c53d5) Invalid blob path specified : ''. Blob identifiers must be in the format 'container/blob'.

Here is the code:

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Upload;
using Google.Apis.YouTube.v3.Data;
using System.Reflection;
using Google.Apis.YouTube.v3;
using Google.Apis.Services;
using System.Threading;

namespace UploadVideoBlob
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task Run([BlobTrigger("video/{name}")]Stream myBlob, string name, Microsoft.Azure.WebJobs.ExecutionContext context, ILogger log)
        {
            UserCredential credential;
            using (var stream = new FileStream(System.IO.Path.Combine(context.FunctionDirectory, "client_secrets.json"), FileMode.Open, FileAccess.Read))
            {
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { YouTubeService.Scope.YoutubeUpload },
                    "user",
                    CancellationToken.None
                );
            }

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
            });

            var video = new Video();
            video.Snippet = new VideoSnippet();
            video.Snippet.Title = "Default Video Title";
            video.Snippet.Description = "Default Video Description";
            video.Snippet.Tags = new string[] { "tag1", "tag2" };
            video.Snippet.CategoryId = "22";
            video.Status = new VideoStatus();
            video.Status.PrivacyStatus = "unlisted";
            var VideoInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", myBlob, "video/*");
            await VideoInsertRequest.UploadAsync();
        }
    }
}

Here is the function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.29",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "blobTrigger",
      "path": "video/{name}",
      "name": "myBlob"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/UploadVideoBlob.dll",
  "entryPoint": "UploadVideoBlob.Function1.Run"
}
1
So you just click the 'run' button?Cindy Pau
@BowmanZhu Yes.user12430088
I have update the answer, please have a look.Cindy Pau

1 Answers

0
votes

Update:

Reproduce your error:

enter image description here

I find your function.json don't have the connection string. Your trigger attribute should be this:

[BlobTrigger("video/{name}", Connection = "str")]

And this is your function.json on portal should be like:

enter image description here

And you should have the application setting in this place:

enter image description here

enter image description here

The key of the setting is str, and the value of the setting is from this place:

enter image description here

Go to your storage account, the connecting string is the value.

Then it works fine, like this:

enter image description here

This is my local.settings.json in VS:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=xxxxxxcore.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "str": "DefaultEndpointsProtocol=xxxxxxcore.windows.net"
  }
}

(Copy the value from your storage account)

Original Answer:

when I publish this function to the portal and run the function.json.

Off Course. From your operation, the error comes from you didn't add a real blob to the container. Blob trigger is not like the httptrigger on portal. Actually, httptrigger on portal will create a request, but blobtrigger on portal will not create a blob for you. You need to add a real blob to the video container.