예제 #1
0
        public async Task <ActionResult> Upload(HttpPostedFileBase file, HomeUploadModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Generate a unique id for the uploaded video
            var videoId = Guid.NewGuid().ToString();

            // ======================================================================
            // Upload Video File to Blob Storage
            // ======================================================================

            // Code Here


            // ======================================================================
            // Save Video info to Cosmos DB Database / Collection
            // ======================================================================

            // Code Here


            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task <ActionResult> Upload(HttpPostedFileBase file, HomeUploadModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Generate a unique id for the uploaded video
            var videoId = Guid.NewGuid().ToString();

            // ======================================================================
            // Upload Video File to Blob Storage
            // ======================================================================

            // Load Connection String to Azure Storage Account
            var videoConnString = ConfigurationManager.ConnectionStrings["videostorage"].ConnectionString;

            if (string.IsNullOrWhiteSpace(videoConnString))
            {
                throw new Exception("The 'videostorage' Connection String is NOT set");
            }

            // Get reference to the Blob Container to upload to
            var storageAccount = CloudStorageAccount.Parse(videoConnString);
            var blobClient     = storageAccount.CreateCloudBlobClient();
            var container      = blobClient.GetContainerReference("video");
            await container.CreateIfNotExistsAsync();

            // Upload Video file to Blob Storage
            var blob = container.GetBlockBlobReference(videoId);
            await blob.UploadFromStreamAsync(file.InputStream);


            // ======================================================================
            // Save Video info to Cosmos DB Database / Collection
            // ======================================================================

            // Save new Document to Cosmos DB for this Video
            var videoRepo = VideoRepositoryFactory.Create();
            var video     = new Video();

            video.Id = videoId;
            // This is added in the function app at input video.VideoId = videoId;
            video.Title              = model.Title;
            video.Description        = model.Description;
            video.ProcessingState    = "Processing";
            video.ProcessingProgress = "0%";
            await videoRepo.Insert(video);


            return(RedirectToAction("Index"));
        }
예제 #3
0
        public ActionResult Upload()
        {
            var model = new HomeUploadModel();

            return(View(model));
        }