ASP - ASP, Upload컴포넌트 활용. 오라클 insert, select 하는 법
제목 : ASP, Upload컴포넌트 활용. 오라클 insert, select 하는 법
I. Upload the File
<form action="formHandler.asp" method="post" enctype="multipart/form-data">
Select a file to upload:
<input type="file" name="binaryFile"> <input type="submit">
</form>
<%
dim up, element, filename
set up = server.createObject("SoftArtisans.FileUp")
up.path = locationToUseForTemporaryFiles
up.save
filename = up.userFilename 'full path on user's machine
filename = mid(filename, inStrRev(filename, "\") + 1) 'chop off the path
%>
II. Read the File from Disk
<%
dim stream
set stream = server.createObject("adodb.stream")
stream.open
stream.type = adTypeBinary
stream.loadFromFile(up.path & filename)
%>
III. Load the Binary Data into the Database
<%
dim conn, rs
set conn = server.createObject("adodb.connection")
conn.open "Provider=OraOLEDB.Oracle;Data Source=oracle.mydomain.com;" _
& "User ID=scott;PASSWORD=tiger;Persist Security Info=True"
set rs = server.createObject("adodb.recordset")
conn.beginTrans
'Use this for an update
conn.execute "UPDATE blobtable SET blobcolumn = empty_blob() WHERE id = 7"
rs.open "SELECT blobcolumn FROM blobtable WHERE id = 7", conn, _
adOpenStatic, adLockOptimistic
'Or this for an insert
conn.execute "INSERT INTO blobtable (id, blobcolumn) " _
& "VALUES (blobtable_seq.nextVal, empty_blob())"
rs.open "SELECT blobcolumn FROM blobtable WHERE id = blobtable_seq.currVal", _
conn, adOpenStatic, adLockOptimistic
rs.fields("blobcolumn").appendChunk(stream.read)
rs.update
rs.close
conn.commitTrans
%>
IV. Retrieve the Binary Data from the Database
<%
dim conn, rs
set conn = server.createObject("adodb.connection")
conn.open "Provider=OraOLEDB.Oracle;Data Source=oracle.mydomain.com;" _
& "User ID=scott;PASSWORD=tiger;Persist Security Info=True"
set rs = conn.execute("SELECT blobcolumn FROM blobtable WHERE id = 7")
'Write it to the browser
response.binaryWrite rs.fields("blobcolumn").value
'Write it to disk
dim stream
set stream = server.createObject("adodb.stream")
stream.type = adTypeBinary
stream.open
stream.write(rs.fields("blobcolumn").value)
stream.saveToFile folderAndFileName, adSaveCreateOverWrite
stream.close
%>
내용 : 이미지 BLOB inesrt, 이후 binary 로 읽어서 write