Trying to get a Blogpost File URL in an event giving object reference error

we tried the below code and ended up with an object reference error

private void Events_AfterUpdateContent(ContentAfterUpdateEventArgs e)
		{
			try
			{
				var content = _contentApi.Get(e.ContentId, e.ContentTypeId);
				var strHtml = content.HtmlName("Web") + " " + GetContent(content) + " " + Tags(e.ContentId, e.ContentTypeId);
				if (Checkcontent(e.ContentTypeId))
				{
					bool isAbused = ValidateContent(strHtml);

					if (isAbused) _abuseController.IdentifyAsAbusive(e.ContentId, e.ContentTypeId);
				}
			}
			catch (Exception)
			{
				throw;
			}
		}

private string GetContent(Content content)
		{

			if(content.ContentTypeId == Apis.Get<IBlogPosts>().ContentTypeId)
			{
				var post = Apis.Get<IBlogPosts>().Get(content.ContentId);
				string body = post.Body("Web");
				Apis.Get<IEventLog>().Write("fileurl " + post.File.FileUrl, new EventLogEntryWriteOptions { });
				body = body + " <img alt=" " src="" + post.File.FileUrl + "" />";
				return body;
			}
			return content.HtmlDescription("Web");
		}

We are getting object references on the line where we are accessing the code  Apis.Get<IEventLog>().Write("fileurl " + post.File.FileUrl, new EventLogEntryWriteOptions { });
  we are uploading the post image while creating the blogpost.

we tested this on 11.1.3 and 11.1.5 , still we faced same issues on both the versions.

Parents
No Data
Reply
  • Former Member
    +1 Former Member in reply to Satish Kumar (3sides)

    How and when are you getting the above file properties? Is this from a REST call after the create has completed, and the File is null while the PostImage is not?

    I've discovered and logged an issue to investigate internally, related to accessing the various file properties of a blog post in AfterCreate events. One alternative is to handle CentralizedFileStorage.Events.AfterCreate to catch when a file is created. This would be separate logic from the rest of your BlogPost AfterCreate logic, and require parsing the path to confirm it's the file for the blog post in question.

    [embed:1a3cced3-af51-49ce-89e2-91f65855cd2d:1a0cbe94-5603-42b4-892b-93f64163d326:id=TE-16972]

Children
No Data