public void TestGCSContentSeviceDelete() { DotNetEnv.Env.Load(); IContentService contentService = new GCSContentService(); // insert content string contentId = contentService.Insert( this.CreateTestContentStream(), "text/plain", prefix: "txt"); // delete content contentService.Delete(contentId, prefix: "txt"); bool hasDeleted = false; try { contentService.EncodeUrl(contentId, prefix: "txt"); } catch { hasDeleted = true; } Assert.True(hasDeleted, "Delete() did not delete object"); }
public ActionResult UpdateFile([FromForm] FileUpdateFormModel formModel) { // validate contents of form model if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // build stream of the uploaded file MemoryStream contentStream = new MemoryStream(); formModel.File.CopyTo(contentStream); // check if content actually exists IContentService contentService = new GCSContentService(); string fileId = formModel.FileId; if (!contentService .HasObject(formModel.FileId, FileController.ContentPrefix)) { return(NotFound()); } // update file with content service fileId = contentService .Update(fileId, contentStream, FileController.ContentPrefix); return(Json(new Dictionary <string, string> { { "fileId", fileId } })); }
public ActionResult UploadFile(IFormFile file) { // build stream of the uploaded file MemoryStream contentStream = new MemoryStream(); file.CopyTo(contentStream); // insert file into content service IContentService contentService = new GCSContentService(); string fileId = contentService.Insert(contentStream, file.ContentType, FileController.ContentPrefix); return(Json(new Dictionary <string, string> { { "fileId", fileId } })); }
public ActionResult GetFile(string fileId) { IContentService contentService = new GCSContentService(); // check if content service has file with the given file id if (!contentService .HasObject(fileId, FileController.ContentPrefix)) { return(NotFound()); } // determine url for file with the given file id using content service string fileUrl = contentService .EncodeUrl(fileId, FileController.ContentPrefix); return(RedirectPermanent(fileUrl)); }
public void TestGCSContentSeviceInsert() { DotNetEnv.Env.Load(); IContentService contentService = new GCSContentService(); string contentId = contentService.Insert( this.CreateTestContentStream(), "text/plain", prefix: "txt"); Assert.False(string.IsNullOrWhiteSpace(contentId), "content id returned from upload is null or empty"); Console.WriteLine("GCSContentServiceTest: " + " TestGCSContentSeviceInsert(): " + " uploaded test content to: " + contentService.EncodeUrl(contentId, prefix: "txt")); // clean up contentService.Delete(contentId, prefix: "txt"); }
public ActionResult DeleteFile(string fileId) { // validate contents of form model if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // remove file using content service // delete only if content actually exists IContentService contentService = new GCSContentService(); if (contentService .HasObject(fileId, FileController.ContentPrefix)) { contentService.Delete(fileId, FileController.ContentPrefix); } return(Ok()); }
public void TestGCSContentSeviceConstructor() { DotNetEnv.Env.Load(); GCSContentService contentService = new GCSContentService(); }