Files
svc-api-x/v1/taffy/examples/api_img/resources/random.cfc
2024-10-23 11:17:42 +03:00

12 lines
640 B
Plaintext

<cfcomponent extends="Taffy.core.resource" taffy_uri="/kitten/random">
<cfdirectory action="list" directory="#expandPath('./images')#" name="variables.images" />
<cfset variables.fileTypes = { jpg="image/jpeg", jpeg="image/jpeg", gif="image/gif", png="image/png", bmp="image/bmp" } />
<cffunction name="get" access="public" output="false">
<cfset var row = randRange(1,variables.images.recordCount) />
<cfset var file = variables.images.directory[row] & "/" & variables.images.name[row] />
<cfreturn streamFile(file).withStatus(200).withMime(fileTypes[listLast(variables.images.name[row], '.')]) />
</cffunction>
</cfcomponent>