Потоковое видео с Azure Функция в C# - PullRequest
0 голосов
/ 26 апреля 2020

Я пытаюсь написать функцию Azure HttpTrigger, которая будет транслировать видео из хранилища BLOB-объектов.

В данный момент у меня есть следующий код, но это не поток.

    [FunctionName(nameof(GetVideo))]
    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "Video/{videoID}")] HttpRequestMessage request,
        ExecutionContext executionContext,
        ILogger log,
        string videoID)
    {
        IActionResult result;

        string storageConnectionString = _configurationSettings.GetStringValue("StorageConnectionString");

        if (!await _blobStorage.BlobExists(storageConnectionString, "Videos", videoID).ConfigureAwait(false))
        {
            result = new NotFoundResult();
        }
        else
        {
            string videoMimeType = _configurationSettings.GetStringValue("VideoMimeType", DefaultVideoMimeType);

            Stream stream = await _blobStorage.GetBlobAsStream(storageConnectionString, "Videos", videoID).ConfigureAwait(false);
            byte[] videoBytes = GetBytesFromStream(stream);

            result = new FileContentResult(videoBytes, videoMimeType);
        }

        return result;
    }

Кто-нибудь может помочь?

1 Ответ

1 голос
/ 28 апреля 2020

Что вы имеете в виду this does not stream, я пытался связать входной BLOB-объект и вернуть его, это удалось. Возможно, вы могли бы сослаться на мой код ниже.

public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Blob("test/test.mp4", FileAccess.Read)] Stream myBlob,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");


            byte[] bytes = new byte[myBlob.Length];

            myBlob.Read(bytes, 0, bytes.Length);
            myBlob.Seek(0, SeekOrigin.Begin);

            var result = new FileContentResult(bytes, "video/mp4");
            return result;

        }

Обновление : Предположим, что вы хотите запросить имя динамического c блоба в HTTP-запросе, вы можете обратиться к приведенному ниже коду Привязать контейнер получить блоб и загрузить его в байты. Я передаю имя BLOB в параметре запроса HTTP.

public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Blob("test", FileAccess.Read,Connection = "AzureWebJobsStorage")] CloudBlobContainer myBlob,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            string filename = req.Query["filename"];
            CloudBlockBlob blob= myBlob.GetBlockBlobReference(filename);

            await blob.FetchAttributesAsync();

            long fileByteLength = blob.Properties.Length;
            byte[] fileContent = new byte[fileByteLength];
            for (int i = 0; i < fileByteLength; i++)
            {
                fileContent[i] = 0x20;
            }
            await blob.DownloadToByteArrayAsync(fileContent, 0);

            var result = new FileContentResult(fileContent, "video/mp4");
            return result;

        }

enter image description here

...