I am trying to create a CAPTCHA image on ColdFusion. ColdFusion will be producing REST services and hence will have to push the image via JSON. I want the image to be self contained. I don't want to expose any of the servers paths, so I am going to encode the image and push that via JSON. Last but not least, Vue.js will be used to show the image on the page.
Note: I have omitted the AJAX part for clarity.
<cfscript>
// This is ColdFusion
tempFile = "ram:///myImage.txt";
myImage = ImageCreateCaptcha(100, 300, "Blackcat", "high");
ImageWriteBase64(myImage, tempFile, "png",true, true);
myfile = FileRead(tempFile);
FileDelete(tempFile);
</cfscript>
<div id="image">
<img :src="captcha">
</div>
<script>
// this is JavaScript
data = { 'captcha' : <cfoutput>'#myfile#'</cfoutput> };
new Vue({
el: '#image',
data : data
});
</script>
Can this process be improved?
1 Answer 1
Be careful with storing intermediate data to disk, including RAM disk. Because it is shared by the whole server, it is even worse than a global variable! The data you write may not be the data you read.