public async Task <IActionResult> Index() { var content = ""; var currentTeacherId = Request.Cookies["teacher"]; // also in BaseController // upload media file with associated teacher if (Request.Method == "POST" && Request.Form.Files.Count > 0) { var uploadedFile = Request.Form.Files[0]; var mediafile = new Mediafile { OriginalFileName = uploadedFile.FileName, Title = uploadedFile.FileName, ContentType = uploadedFile.ContentType, TeacherId = currentTeacherId }; var mediafileId = await firestoreProvider.AddMediafileAsync(mediafile); using (var memoryStream = new MemoryStream()) { await uploadedFile.CopyToAsync(memoryStream); var obj = new Storagefile { Name = mediafileId, // Path.GetExtension if we want the .mp4 ContentType = uploadedFile.ContentType, // content type is set so we don't really need the extension Metadata = new Dictionary <string, string> { { "OriginalFileName", uploadedFile.FileName } } }; var upload = await storageProvider.UploadObjectAsync(obj, memoryStream); ViewBag.uploadedData = upload; } } // display list of media files for current teacher if (!String.IsNullOrEmpty(currentTeacherId)) { var listFiles = await firestoreProvider.GetMediafilesByTeacherIdAsync(currentTeacherId); listFiles.Select(c => { c.HumanTime = Utility.RelativeDate(c.CreatedDateTime); return(c); }).ToList(); listFiles.Sort((y, x) => DateTime.Compare(x.CreatedDateTime, y.CreatedDateTime)); // newest first ViewBag.listFiles = listFiles; ViewBag.bucketName = storageProvider.bucketName; } ViewBag.content = content; return(View()); }
public async Task <string> UploadObjectAsync(Storagefile file, MemoryStream memoryStream) { var obj = new Google.Apis.Storage.v1.Data.Object { Bucket = bucketName, Name = file.Name, ContentType = file.ContentType, Metadata = file.Metadata }; var upload = await storage.UploadObjectAsync(obj, memoryStream); return(upload.MediaLink); }