Solved

Upload file and data to database

Posted on 2014-02-19
6
400 Views
Last Modified: 2014-02-20
Hi Experts,

I've got 20 documents with over 114 concurrent questions about 36 each. So I've put them in a table in my database and I've made ajax drag and drop interface so document management is easy.

The input part ready but now I have to complete the part that saves all fields into the database.

Because every document has a file upload field I guess I can't use request.from.

This is my best try:

<!--#INCLUDE FILE="config.asp"-->
<!--#INCLUDE FILE="requestobjects.asp"-->
<%
Server.ScriptTimeOut = 300
Response.Buffer = False
Dim oPseudoRequest 
Set oPseudoRequest = new PseudoRequestDictionary
oPseudoRequest.ReadRequest()
oPseudoRequest.ReadQuerystring(Request.Querystring)
documentID= SQLEncode(oPseudoRequest.Form("docmentID"))

' Eerst uitvragen aan de database wat we voor dit document moeten opslaan
sql="SELECT DISTINCT entree_items.valuename, entree_fieldtypes.datetype FROM entree_fieldtypes INNER JOIN (entree_items INNER JOIN entree_ItemPerDocument ON entree_items.fieldtypeID = entree_ItemPerDocument.itemID) ON entree_fieldtypes.fieldtypeID = entree_items.fieldtype WHERE entree_ItemPerDocument.documentID=1;"
'response.write sql
'response.end
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQL, cs
teller=0
sSQL = "SELECT * FROM entree_fase1"
Set oRS = Server.CreateObject("ADODB.RecordSet")
oRS.Open sSQL, cs, 1, 3
oRS.AddNew
Do While Not RS.EOF
	if RS("datetype") = "image" then
		oRS(RS("valuename")).AppendChunk oPseudoRequest.Form(RS("valuename")).Binary 
	else 
		oRS(RS("valuename")) = SQLEncode(oPseudoRequest.Form(RS("valuename")))
	end if

RS.MoveNext
Loop
oRS.Update
oRS.Close
Set oRS = Nothing

response.redirect("default.asp")

Function SQLEncode(ByVal s)
	SQLEncode = Cstr("" & s)
	SQLEncode = Replace(SQLEncode,"'","''")
End Function
Set oPseudoRequest = Nothing
cs.Close
Set cs = Nothing
%>

Open in new window



As you can see I use Sybe Vissers pure ASP upload but I can't get lines 25 or 27 to work. I try to inject the fieldname from recordset RS  into the recordset oRS.

What should be my syntax? Or am I completely wrong here?

Thanks?
0
Comment
Question by:Steynsk
  • 3
  • 3
6 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 39870724
Because every document has a file upload field I guess I can't use request.from.

why not? :)

how are the file upload fields named? I assume they all have some sort matching text, maybe like fileUpload1, fileUpload2, fileUpload3, etc. if thats the case, you can just loop through the Request.Form object and grab the field names that way:

for each fileName in Request.Form
    if InStr( fileName, "fileUpload" ) > 0 then    '-- this is a file field
          theFile = Request.Form( fileName )
          '-- process the file however
    end if
next

Open in new window

0
 
LVL 1

Author Comment

by:Steynsk
ID: 39871187
But will that upload my file into datsbase as a blob file? (Date type "image" in ms sql).
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 39871220
the code i gave you is just a method in which you can get each file to the server using Request.Form. however you save it is up to you, but if it were up to me, I would save the files to some folder on your site (maybe call it /uploads/) and save the path to the file in the database.

This is a lot more efficient, and a lot easier to code than appending file chunks to the database
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:Steynsk
ID: 39871386
I understand but the files uploaded are scanned passport an id cards and should be stored more secure than basic. But maybe i should first upload them to a upload folder on the webserver and then post proces them to a blob in my db. I will search for a scrip to make this post proces work.
Maybe you have me led to an alternative solution that will solve my problem. I'll give it a try and get back to you.
0
 
LVL 32

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 39871477
just keep in mind it's going to put a heavy load on your database server, as once you get the files in the database, you still need to stream them out, which the database will need to do. If you do go this route, I agree that first getting the files uploaded first, then processing them is the right approach.
0
 
LVL 1

Author Closing Comment

by:Steynsk
ID: 39873213
thanks for the advise
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Passing special characters in http get request 7 39
if form parameter is null redirect 2 53
Classic ASP error- Object required: 'objFolder' 6 36
INNER JOIN ? 8 41
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now