public void CreatePipeline(CreatePipelineRequest request) { var pipeline = request.Pipeline; var generatedName = _storageManager.HashMd5(pipeline.Name); var cloudBlockBlob = _storageManager.CreateNewFile(generatedName + ".json", _containerName).Result; var salt = ""; while (cloudBlockBlob == null) { salt += _storageManager.RandomString(); generatedName = _storageManager.HashMd5(pipeline.Name + salt); cloudBlockBlob = _storageManager.CreateNewFile(generatedName + ".json", _containerName).Result; } cloudBlockBlob.Metadata.Add(new KeyValuePair <string, string>("originalName", pipeline.Name)); if (!IsNullOrEmpty(salt)) { cloudBlockBlob.Metadata.Add(new KeyValuePair <string, string>("salt", salt)); } var newPipeline = new Pipeline { Id = generatedName, Name = pipeline.Name, Tools = pipeline.Tools }; UploadPipelineToStorage(newPipeline, cloudBlockBlob); }
public async Task StoreVideo(IFormFile video) { if (video == null) { return; } //create storage name for file var generatedName = _storageManager.HashMd5(video.FileName); var cloudBlockBlob = _storageManager.CreateNewFile(generatedName + ".mp4", _containerName).Result; var salt = ""; while (cloudBlockBlob == null) { salt += _storageManager.RandomString(); generatedName = _storageManager.HashMd5(video.FileName + salt); cloudBlockBlob = _storageManager.CreateNewFile(generatedName + ".mp4", _containerName).Result; } cloudBlockBlob.Metadata.Add(new KeyValuePair <string, string>("originalName", video.FileName)); if (!IsNullOrEmpty(salt)) { cloudBlockBlob.Metadata.Add(new KeyValuePair <string, string>("salt", salt)); } //create local temp copy of video file and thumbnail //var baseDirectory = "d:\\local\\"; var baseDirectory = Directory.GetCurrentDirectory() + "\\"; var thumbnailPath = baseDirectory + "thumbnail.jpg"; var videoPath = baseDirectory + video.Name; await using var stream = new FileStream(videoPath, FileMode.Create); await video.CopyToAsync(stream); //get video thumbnail and store as separate blob /*var inputFile = new MediaFile {Filename = videoPath}; * var thumbnail = new MediaFile {Filename = thumbnailPath}; * using (var engine = new Engine()) * { * engine.GetMetadata(inputFile); * var options = new ConversionOptions {Seek = TimeSpan.FromSeconds(1), VideoSize = VideoSize.Cif}; * engine.GetThumbnail(inputFile, thumbnail, options); * }*/ if (!File.Exists(thumbnailPath)) { File.Create(thumbnailPath).Close(); } var thumbnailBlockBlob = _storageManager.CreateNewFile(generatedName + "-thumbnail.jpg", _containerName).Result; thumbnailBlockBlob.Properties.ContentType = "image/jpg"; await thumbnailBlockBlob.UploadFromFileAsync(thumbnailPath); //get video duration in seconds //var seconds = Math.Truncate(inputFile.Metadata.Duration.TotalSeconds); var seconds = 0; cloudBlockBlob.Metadata.Add(new KeyValuePair <string, string>("duration", seconds.ToString())); //upload to Azure Blob Storage var ms = new MemoryStream(); await video.CopyToAsync(ms); var fileBytes = ms.ToArray(); cloudBlockBlob.Properties.ContentType = video.ContentType; await cloudBlockBlob.UploadFromByteArrayAsync(fileBytes, 0, (int)video.Length); }