Copy link to clipboard
Copied
I have Users Upload files and they are stored in the database as binary file with cf_sql_blob type, it could be a word doc or pdf file but not images
The content type I am storing in the database also. How do I make this file viewable on the browser?
Copy link to clipboard
Copied
Run a SELECT to retrieve the binary data. Then use cfcontent to return it to the browser.
The forum eats tags. So fix up as needed
ie
[cfheader name="Content-Disposition" value="inline; filename=theFilenameYouWant.ext"]
[cfcontent type="(mime type of current file)" variable="#binaryData#"]
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c82.html
Copy link to clipboard
Copied
What if I want to open it with a Cffile tag
Copy link to clipboard
Copied
What if I want to open it with a Cffile tag
Read the documentation and see how the cffile tag works?
Copy link to clipboard
Copied
Read the documentation and see how the cffile tag works?
Do not confuse things by using logic
Copy link to clipboard
Copied
Do not confuse things by using logic
I am foolish, irresponsible and wholeheartedly and unreservedly apologise. Seriously though, I wish I'd been sent the memo about the sudden influx of people who'd all been given ColdFusion jobs dispite them having no previous skills in the subject, and the other one about Google being inaccessible would've been a handy heads-up too.
Copy link to clipboard
Copied
and the other one about Google being inaccessible would've been a handy heads-up too.
Haha I do not mind it if someone is so new they are not aware of the documentation. Or they did read the docs but had questions about parts of it. But yeah, there have been quite a few recent posts that do not give any indication of being the former or the latter ..
Copy link to clipboard
Copied
What if I want to open it with a Cffile tag
Not sure I follow. Use it to do what? If your files are stored on disk (not in a database) then yes you technically could use cffile to read the binary data. Then use cfcontent to display it. But normally you would not do that. It is more efficient to skip the cffile call and use cfcontent's "file" attribute instead of "variable"
Copy link to clipboard
Copied
How do I make this file viewable on the browser?
Bear in mind that whilst this will work for a PDF, a Word doc will just prompt for download.
Copy link to clipboard
Copied
How do I make this file viewable on the browser?
>> Bear in mind that whilst this will work for a PDF, a Word doc will just prompt for download.
All depends on the browser settings. If the user's browser is capable of displaying the returned file "inline" it will. Otherwise, the user will be prompted to download / open the file.