I have an azure function that returns an image of my top blog from my feed. Now I have just added that function URL as the image src as below in the Readme.md
file.
<img src="https://getlatestposts.azurewebsites.net/api/GetLatestPosts?code=VS4fy5DNxpj8/SUS0Chp0aGBux36c9OyOg5KhmSjh5dPVBvCaVaEuA==">
But the image is not loading at all, and when I check the HTML generated, I could see that the src is been updated with some weird URL from "https://camo.githubusercontent.com". There is also an additional a tag
introduced.
Anyone else faced this issue?
Finally, I was able to fix this issue. What I did is that, I returned a File Stream
from my Azure Function, instead of returning a base64
string. Below is my Azure function.
[FunctionName("GetLatestPosts")]
public static FileStreamResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest request, ILogger log) {
try {
var baseString = WriteOnImage(GetLatestFeeds());
// Had to do this, as it was throwing error "The input is not a valid Base-64 string as it contains a non-base 64 character"
string convert = baseString.Replace("data:image/png;base64,", String.Empty);
var bytes = Convert.FromBase64String(convert);
var result = new FileStreamResult(new MemoryStream(bytes), Configuration.ContentType);
log.LogInformation("Returning stream now!");
request.HttpContext.Response.Headers.Add("Cache-Control", "s-maxage=1, stale-while-revalidate");
return result;;
} catch (System.Exception ex) {
log.LogError($ "Something went wrong: {ex}");
throw ex;
}
}
I did write an article about this entire application, you can read it here. It contains the GitHub repositories too, just in case, if you are interested.