How to store a Word document as a BLOB in mySQL with Coldfusion
A client wants Word documents saved to a mySQL database despite me arguing against. The documents themselves should not be particularly large, no more than 1 MB each. I have enabled BLOB in CF administrator and set the blob buffer to 1,000,000
Here's my SQL
<cfset newMessageID=1569>
<cfset fileName="c:\temp\0.doc">
<cffile action = "readbinary"
file = "#fileName#"
variable = "fileData">
<cfquery name="addFile" datasource='#application.dsn#'>
INSERT into files (fileID, fileData)
Values (#newMessageID#, <cfqueryparam value="#f开发者_开发百科ileData#" cfsqltype="CF_SQL_BLOB">)
</cfquery>
I get "Data truncation: Data too long for column 'filedata' at row 1" error. The filedata field in the files table is definitely set to blob. What am I doing wrong?
CF 9.01, mySQL 5.4
What am I doing wrong
What kind of blob? There are different types including long and medium blob. Blob is (approximately) 2^16 = 65,536 bytes, medium blob is 2^24 = 16,777,216 bytes. If you think you might exceed medium blob, then go with longblob ie 2^32.
Just a bad, bad idea.
I would either:
Convert it to text file 1st, then you simplify the importing of just raw text.
Or just upload it to some folder, and make it available for downloading again or viewing online
your cutting your own throat trying to store it in the database...
精彩评论