ColdFusion 9 and filestream - sql-server-2008

I have an application that allows users to upload files. Right now it is uploading directly to the file system. I have my database set up to use filestream (in SQL Server 2008). I have a form with an input field type of file.
<input type="file" name="ul_path1" id="ul_path1">
that allows the user to select the file. I then tried to use the files name selected to do a query to insert the file into the database.
<cfquery datasource=#ODSN# name="upFiles">
insert into redbook_uploads
'#session.buildno#', '#form.ul_path1#', Cast('#form.ul_path1#' As varbinary(max))
</cfquery>
But I get an error right before #form.u1_path1# and in the error message it shows the SQL statement as
insert into redbook_uploads '009', 'C:\apps\ColdFusion9\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp7306602622243140924.tmp', Cast('C:\apps\ColdFusion9\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp7306602622243140924.tmp' As varbinary(max))
when it should be:
insert into redbook_uploads '009', 'C:\users\username\file.pdf', Cast('C:\users\username\file.pdf' As varbinary(max))
I can't figure out how to get the actual file name and am not sure why it's not getting it.

This forum post might have the correct answer:
Here are the basic steps for uploading a file and storing it in your database.
Create a page with a form that includes a file tag. This form will submit to an 'action.cfm' page. Note the name of the .cfm page is not important, 'action.cfm' is an example.
On your 'action.cfm' use CFFILE with action="upload" tag to save the file to your filesystem.
Use the CFFILE tag with action="readbinary" to read the contents of the uploaded file into a variable. You may also want to use CFFILE to delete the uploaded file after it has been read into a variable.
Use CFQUERY with CFQUERYPARAM to insert the file conents.

For whatever reason, the path to the file is defaulting to:
C:\apps\ColdFusion9\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp###.tmp.
We need to see some code to provide a more specific answer. But to answer part of your question ...
Newly uploaded files are always placed in a server temp directory and given a temporary file name. On your action page, you must use cffile action=upload tag to move the file from the temp directory to the desired location.
The action name is a bit misleading. It does not really upload anything. As you can see from the temporary path, the file was already uploaded to the server. All action=upload does is to move/rename the file. It also populates the CFFILE (or result) structure with details about the file, such as it is name, file extension, mime type, etcetera. (For more details, see the documentation.) Those values can be used to save file information to your database.
<cffile action="upload"
fileField = "form.nameOfYourInputField"
destination = "c:\path\to\target\directory"
nameConflict = "makeUnique"
result="fileDetails" />
<cfdump var="#fileDetails#" label="Uploaded File Details">

Related

mysql using the command line client- Image Loading

I am trying to load an image into mysql using the command line client and following is the the code that i have been using;
INSERT INTO AutomobileParts (Part_ID, Part_Name,Img_Path)
VALUES (
"101AA",
"BikePanel",
load_file("F:/PYQT Projects/bikepanel.jpg")
) WHERE i=1;
can someone please help me out in understanding as in where i am going wrong on entering this piece of code.
MySQL LOAD_FILE() reads the file and returns the file contents as a string.
That will probably not work with an image I guess.
Your field name "Img_Path" indicates that you only save the path in that field, not the image, and that the image itself is on your file system # F:/PYQT Projects/bikepanel.jpg. This would be the normal way of saving images: The image file itself is in some folder on your server and you save the path to that folder in your table.
So if you want to show the image you would select the saved path from your MySQL table and read the file with your respective programming language (e.g. PHP or whatever you are using).
This might do the job unless there is an issue with variable "i" below:
INSERT INTO AutomobileParts (Part_ID, Part_Name,Img_Path)
VALUES (
"101AA",
"BikePanel",
"F:/PYQT Projects/bikepanel.jpg"
) WHERE i=1;

My schema.ini file is being ignored when using DoCmd.TransferText() from .Net

My schema.ini file is being ignored.I get the same results whether I have a scheme.ini file in the same folder as my tab file or not. All of the columns end up in a single column. I am trying to use a schema.ini as I am importing tab delimited files. The results make perfect sense if it is trying to import a comma delim file.
So my postulate is that the schema.ini file is just being ignored.
I am running Access from a .Net program using Microsoft Access 14.0 Object.Library.
I am using this command from .net:
Access.DoCmd.TransferText( Microsoft.Office.Interop.Access.AcTextTransferType.acImportDelim, , TableName, TabFile, HasFieldNames)
Here is my schema.ini file, not that it matters since it is being completely ignored:
[impacts.txt]
Format=TabDelimited
ColNameHeader=True
MaxScanRows=0
Clues? Thanks!
EDIT:
I tried running this from within an Access Module with the same results.
I tried editing the registry to change the Format value there. Same results.
Consider an action query, either append or make-table, as the use of schema.ini files can work directly in an Access query of a text file. Below assumes .ini file is in same directory as text file.
INSERT INTO mytableName
SELECT * FROM [text;Database=C:\Path\To\Text\File].[impacts.txt]
SELECT * INTO newtableName FROM [text;Database=C:\Path\To\Text\File].[impacts.txt]

XML to phpmyadmin

I want to import a XMl file into phpmyadmin.
I have a XML file with 75000 lines so inserting individually the values is a huge no, when I try to import the file as XMl to the database it gave the following message:
Import has been successfully finished, 0 queries executed.
The following structures have either been created or altered. Here you can:
View a structure's contents by clicking on its name.
Change any of its settings by clicking the corresponding "Options" link.
Edit structure by following the "Structure" link.
wp_db (Options)
(xmlfile.xml)
-----------------------------------------------------------------------
Notice in ./libraries/plugins/import/ImportXml.php#158
Undefined index: pma
Backtrace
./import.php#652: PMA\libraries\plugins\import\ImportXml->doImport(array)
The phpmyadmin is behind MAMP, a short version of the xml file looks like this:
<Report>
<Row1>
<Reference>123</Reference>
<Nature>Outside</Nature>
<Disponibility>Full</Disponibility>
<State>In progress</State>
<Person>Jon</Person>
<Seller></Seller>
</Row1>
<Row2>
<Reference>123</Reference>
<Nature>Outside</Nature>
<Disponibility>Full</Disponibility>
<State>In progress</State>
<Person>Jon</Person>
<Seller></Seller>
</Row2>
</Report>
If it's not possible at least what is the easiest way to do it?
Thanks!
phpMyAdmin supports importing XML only if it follows a special format. You can see the exact format by exporting in phpMyAdmin a table in XML. You would need to programmatically modify your existing file to adapt to the supported format.

How can I store text file in MYSQL database using QT?

I have a table which has two columns: ID, FILE;
The FILE column has BLOB type;
I want to store the full file in the database not the content of the file.
I would like to download the file later as file_name.txt
This is how I tried but after insert the FILE is NULL;
query.exec("INSERT INTO test(ID, FILE) VALUES(1, LOAD_FILE('/home/nemeth/Documents/list.txt'));
According to
MySQL documentation on LOAD_FILE(), the file must satisfy some conditions to be loaded. Not only being local but also permissions and stuff.
LOAD_FILE(file_name)
Reads the file and returns the file contents as a string. To use this
function, the file must be located on the server host, you must
specify the full path name to the file, and you must have the FILE
privilege. The file must be readable by all and its size less than
max_allowed_packet bytes. If the secure_file_priv system variable is
set to a nonempty directory name, the file to be loaded must be
located in that directory.
If the file does not exist or cannot be read because one of the
preceding conditions is not satisfied, the function returns NULL.
The character_set_filesystem system variable controls interpretation
of file names that are given as literal strings.
Also have you tried searching a little?... Lookie here :p
I could not figure out what is the problem so I solved differently.
I've read the file into a QByteArray and inserted the array into the database.
QByteArray byteArray = file.readAll();
QSqlQuery query;
query.prepare("INSERT INTO TEST_TABLE(ID, FILE) VALUES (1,?)");
query.addBindValue(byteArray);
query.exec();

How do I use LOAD_FILE to insert value from a file into a table?

I tried to insert a text file into my database, using this code:
INSERT INTO test.table (url_address, html)
VALUES ('abc', LOAD_FILE('C:\Documents and Settings\eran\Desktop\1.txt'));
However, I get null in the html column. How can I get the data from the text file to my database?
MySQL LOAD_FILE() reads the file and returns the file contents as a string.
To use this function, the file must be located on the host server, user must specify the full path name of the file, and user must have the FILE privilege. The file must be readable and size must be less than max_allowed_packet (set in the my.ini file) bytes. It returns NULL if the file does not exist or can’t be read.
Try using double back slash "\" for the path. I do not know if it will work.
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_load-file
http://www.w3resource.com/mysql/string-functions/mysql-load_file-function.php