Copy link to clipboard
Copied
Hello, everyone.
I've got the file uploading to the database, and that is working most excellent.
How do I get it to open/save immediately without first using CFFILE action="write" to save it to a server folder, first?
I'm using the following code:
<cfcontent variable="#getFile.contents#" reset="true"><!--- binary data for file, pulled from "varbinary(max)" --->
<cfheader name="content-disposition" value="attachment;filename=#getFile.fileName#">
<cfheader name="content-type" value="application/octet-stream">
<cfoutput>#toString(getFile.contents)#</cfoutput>
<cfabort>
.. but all this does is open a dialogue asking the user to either open or save the CFM file calling it, but the .cfm is replaced with .ZIP.
The files are not all going to be the same MIMEtype - some will be Word documents, some Excel documents, some PowerPoint documents, and some PDF documents.
^_^
Copy link to clipboard
Copied
The point of using the VARIABLE attribute of CFCONTENT is so that you don't have to explicitly output the value later on. Here's an example:
http://awads.net/wp/2006/01/25/savingdownloading-files-tofrom-oracle-using-coldfusion/
(scroll down to the part of the page that discusses the output of the content)
As far as the prompt that the user receives, you can't really do anything about that. The user has to choose whether to download the file at all, and whether to open or save the downloaded file.
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/
Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
Read this before you post:
http://forums.adobe.com/thread/607238
Copy link to clipboard
Copied
Sorry.. I didn't make myself clear. As far as the prompting to either save or open the file, that's what I expect. What I wasn't expecting was the fact that the file that is prompted to open or save is the name of the ColdFusion document that is trying to execute. (ie, the CFM document is called "details_supplier_docs_open.cfm" and when executed it prompts the user to open or save "details_supplier_docs_open.cfm" instead of "this_requested_excel_file.xlsx".)
Copy link to clipboard
Copied
I think there may a few problems. But the point about cfcontent stands. You are using it incorrectly. Take a look at the example in the link. Notice how the cfheaders are positioned first, then the cfcontent?
Copy link to clipboard
Copied
I'm following the example in the link. Now it will use the proper filename when asking to open or save; however, when opening, I get the following:
If I click OK, it happens two or three more times; the file does eventually open, with some lost formatting. Do I need to do any converting?
Thank you,
^_^
Copy link to clipboard
Copied
It is hard to say what should happen without knowing more about what file type you are testing, what programs are installed on your test computer, etcetera.
Copy link to clipboard
Copied
Filetypes that can be uploaded into the database are PDF, PPT, DOC/DOCX, and XLS/XLSX (PDF, PowerPoint, Word, Excel). I am setting the MIMEtype by using a CFC I built that creates an array of extensions and the MIMEtypes they are associated with (for example, if the filename ends in .DOCX, the array returns a MIMEtype of "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; if the filename ends in .DOC, the array returns a MIMEtype of "application/msword"; if the filename ends in .PDF, the array returns a MIMEtype of "application/pdf". The CFCONTENT tag is then set for that type.)
This is an internal web app that cannot be accessed outside of this network. Every computer that has access to it has Office 2007 installed, as well as Adobe Reader, so when given the option to open or save, the "open" is always associated with the proprietary application (.xls is always given an option for Microsoft Excel; .docx is always given an option for Microsoft Word; etc.)
Theoretically, once the binary of the Excel/Word/PowerPoint/PDF file is stored in the database, I should be able to read that binary data, give it the CFCONTENT and CFHEADER tags that it needs, and it should download and save, or open in the native application (this much is working.) What is confusing me is why the applications feel that the files are corrupted and need to be recovered. The file is being insert as binary, being retrieved as binary. What _could_ cause the data to be misconstrued as corrupted? I'm _not_ using TRIM for insert or select, or any kind of encoding/decoding.
^_^
Copy link to clipboard
Copied
Well, Wireshark and tools like that are your friends here. What's different between the byte stream you get when you download through CF versus downloading the same file directly?
Also, do you have any output in Application.cfc/cfm?
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/
Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
Read this before you post:
http://forums.adobe.com/thread/607238
Copy link to clipboard
Copied
There is no cfoutput or any kind of visible display in the application.cfm file. Just a function to deny access if during database downtime; the CFAPPLICATION tag; a function that grabs the intended URL to redirect to after secure logon; the security check/logon redirect; a few variables are being set (database access, error handling, etc.) That's it.
Never heard of Wireshark. I'll look into it.
^_^
Copy link to clipboard
Copied
New requirement for this was just handed to me. Now they want it so that when a file is clicked on, it will open as "read only".
Is that possible when pulling binary data from the database??
^_^
Copy link to clipboard
Copied
NOT ON MY SYSTEM (i.e. the user downloading the file) IT IS NOT!
You can make it read only on the server, but that really doesn't do much, if you allow it to be downloaded. Because it is a copy that is downloaded and I get to decide the file permissions on any data I save to my file system.
What you may want to start considering is creating PDF files out of these data files. You can't make the PDF file itself read only, but you can password protect and make the content of the PDF file read only. So at least it is somewhat tricky to copy and paste data out of the file.
Copy link to clipboard
Copied
NOT ON MY SYSTEM (i.e. the user downloading the file) IT IS NOT!
Didn't think so. Anyone who has basic access to this web app can review the documents, but only admins can upload/edit these documents, so it seems kind of ridiculous, to me, to require they be "read only".
^_^
Copy link to clipboard
Copied
WolfShade wrote:
so it seems kind of ridiculous, to me, to require they be "read only".
The usual BS reason I hear for this requirement is the content creator(s) don't want their content copyable to other documents users may want to create with the data.
If you don't want your data copied, don't put it on the Internet. Want your data on the Internet, it has to be copyable. Those are really the only options.
I smile to myself at these sites that have these elaborate techniques to "protect" the content of the site. Techniques that probably earned some developer(s) somewhere a nice paycheck by these developer(s) telling the content creators how their system will protect content from all* users.
With the asterisk probably never being properly defined as "All users who don't want to copy your content in the first place! Because nearly every user who will want to copy your content will know enough about how the Internet and web actually work and can easily bypass anything we put into place to protect your content".
Copy link to clipboard
Copied
Your code seems unnecessarily complex. In the following example, the file p.pdf is in the dir directory on my desktop. I wish to offer it to the client for download, as the file abracadabra.pdf.
<!--- read the PDF as a binary --->
<cffile action = "readBinary" file = "C:\Documents and Settings\bkbk\Desktop\x\p.pdf" variable ="pdfBinaryObj">
<!--- offer the PDF for download --->
<cfheader name="Content-Disposition" value="attachment;filename=abracadabra.pdf">
<cfcontent variable="#pdfBinaryObj#" type="application/octet-stream; charset=UTF-8">
Find more inspiration, events, and resources on the new Adobe Community
Explore Now