public async Task <List <Video> > Upload(IFormFileCollection videoFiles, ICollection <string> thumbnails)
        {
            var videoList = new List <Video>();
            var thumbs    = thumbnails.ToArray();

            // Upload each file
            for (int i = 0; i < videoFiles.Count; i++)
            {
                var video = videoFiles[i];

                // Create full filename with id and extension as well
                var    extension       = '.' + video.ContentType.Split('/').Last();
                var    fileNameNoSpace = video.FileName.Replace(' ', '-');
                string newId;
                string fullFileName;

                // Make sure the video name does not exist, otherwise it will be overwritten
                do
                {
                    newId        = Guid.NewGuid().ToString();
                    fullFileName = newId + '.' + fileNameNoSpace + extension;
                } while (await _videoRepo.Exists(fullFileName));

                // Convert blob to stream and upload
                var stream       = video.OpenReadStream();
                var fileLocation = await _videoRepo.Upload(fullFileName, stream);

                // Create a new Video to add to the list of metadata that will be returned
                videoList.Add(new Video
                {
                    Id           = newId,
                    Title        = video.FileName,
                    FileLocation = fileLocation,
                    Thumbnail    = thumbs[i]
                });
            }

            return(videoList);
        }
Пример #2
0
 public async Task <bool> VideoExists(long videoId)
 {
     return(await _videoRepository.Exists(videoId));
 }