Hello! Today I have a question about serving files...
# cfml-general
j
Hello! Today I have a question about serving files with ColdFusion. I need to load images from a secured network drive into an HTML document on my Coldfusion server. I understand that because the network drive is not part of the webroot, this is not an option and is considered a security feature to protect the files that live on the network drive and server. I have done some research and found these solutions: https://stackoverflow.com/a/46003218/16511184 https://www.tek-tips.com/viewthread.cfm?qid=935379 These solutions both mention the use of server-side code to access images, as the server should have permission to access files on the network drive. My question is, how do I deliver the images to the HTML document, and in ColdFusion? My naiive guess was to just grab the image name from a query made on the server, but just slotting the name into the img tag's src attribute creates the original issue of client trying to access an image on the network drive they don't have permission to view.
s
You should be able to do something similar to the stack overflow PHP example by using cfcontent to read the file, then return it to the browser. https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-c/cfcontent.html
t
So what the stack overflow answer is doing is making a link to a page (in the answer it's php, but it could just as easily be coldfusion). It's not a link to the image itself. The job of this intermediate page is to fetch the image from it's actual location, and then serve it to your webpage. The code for this page is fairly straightforward:
Copy code
<cfcontent file="\\path\to\file.jpg", type="image/jpg">
f
There are also some web server plugins that let you specify a http response header, like
X-Sendfile: \\path\to\file.jpg
then IIS for example would serve/read the file if you want to avoid having CF serve the file directly, but still authorize access to it
e
You could use CFCURL, https://github.com/iGLOO-be/cf-curl to get the object, then just do a cfdocument or cffile write to create the file you need and move it to where ever you need it.