// deletes the content specified by content id from the contentService // Optionally a directory prefix to the object being inserted public void Delete(string contentId, string prefix = "") { // peform removal of object using GCS string objectName = GCSContentService.BuildObjectName(prefix, contentId); this.storage.DeleteObject(this.bucketName, objectName); }
// Encode the given content id in to a url so that can be used to // retrieve the content given the content id returned by // Insert()/update() // Optionally a directory prefix to the object being inserted public string EncodeUrl(string contentId, string prefix = "") { // get media link using GCS string objectName = GCSContentService.BuildObjectName(prefix, contentId); var storageObject = this.storage.GetObject(this.bucketName, objectName); return(storageObject.MediaLink); }
/* IContentService interface */ // Insert the content in the given contentStream to the content service // returns a content id string which can be used to retrieve the content // contentType provides a MIME content type & a prefix to the path // Optionally a directory prefix to the object being inserted public string Insert(Stream contentStream, string contentType, string prefix = "") { // generate object nae for the new content string contentId = Guid.NewGuid().ToString(); string objectName = GCSContentService.BuildObjectName(prefix, contentId); // perform the upload using GCS this.storage.UploadObject( this.bucketName, objectName, contentType, contentStream); return(contentId); }
// Check if the content service has the content given by content id // returns true if the content exists, otherwise false public bool HasObject(string contentId, string prefix = "") { try { string objectName = GCSContentService.BuildObjectName(prefix, contentId); this.storage.GetObject(this.bucketName, objectName); } catch { return(false); } return(true); }
// Updates the content in the given contentStream to the content service // specified by contentId // returns a content id string which can be used to retrieve the content // Optionally a directory prefix to the object being inserted public string Update(string contentId, Stream contentStream, string prefix = "") { // perform the upload of updated file using GCS string objectName = GCSContentService.BuildObjectName(prefix, contentId); var storageObject = this.storage.GetObject(this.bucketName, objectName); // remove existing object this.Delete(contentId, prefix); // update object this.storage.UploadObject( this.bucketName, objectName, storageObject.ContentType, contentStream); return(contentId); }