/// <summary> /// Add an attachment to an entity /// </summary> /// <param name="id">id of entity</param> /// <param name="filePathAttachment">file path of the file to attach</param> /// <param name="contentType">type of the file to attach</param> /// <param name="attachmentName">identify of the file to attach</param> public override void AddAttachment(string id, Stream fileStream, string contentType, string attachmentName) { var existingEntity = this.database.GetExistingDocument(GetInternalCBLId(id)); if (existingEntity == null) { throw new KeyNotFoundNoSQLException(); } IUnsavedRevision newRevision = existingEntity.CurrentRevision.CreateRevision(); newRevision.SetAttachment(attachmentName, contentType, fileStream); newRevision.Save(); }
/// <summary> /// Remove the attachment of a document /// </summary> /// <param name="id">id of entity</param> /// <param name="attachmentName">name of attachment to remove</param> public override void RemoveAttachment(string id, string attachmentName) { var existingEntity = this.database.GetExistingDocument(GetInternalCBLId(id)); if (existingEntity == null) { throw new KeyNotFoundNoSQLException(string.Format("Entity '{0}' not found", id)); } if (!AttachmentExists(existingEntity.CurrentRevision, attachmentName)) { throw new AttachmentNotFoundNoSQLException(string.Format("Attachement {0} not found on Entity '{1}'", attachmentName, id)); } IUnsavedRevision newRevision = existingEntity.CurrentRevision.CreateRevision(); newRevision.RemoveAttachment(attachmentName); newRevision.Save(); }