ASP (클래식) 예제
주의
서버 보안을 위해 파일 업로드 및 문서 임포트 처리를 구현할 때 아래 가이드를 참고합니다.
1. 이미지 / Video / 파일 업로드
주의
아래 샘플 코드의 파일 업로드 부분은 의도적으로 최소화되어 있으며, 적절한 보안 처리가 적용되어 있지 않습니다.
파일 업로드는 프로젝트에 이미 구현된 기능을 사용하고, 아래 코드는 에디터 연동 부분만 참고합니다.
파일 업로드는 TABS Upload5를 사용합니다. 실제 ASP 환경에 통합할 때는 운영 환경에 이미 배포된 파일 업로드 컴포넌트를 사용합니다.
<%@ CodePage=65001 Language=VBScript %>
<% Option Explicit %>
<%
On Error Resume Next
Dim UPLOAD_PATH
UPLOAD_PATH = "C:\inetpub\wwwroot\upload"
Dim Upload, fileName
Set Upload = Server.CreateObject("TABSUpload4.Upload")
Upload.CodePage = 65001
Upload.Start "C:\TEMP"
Upload.Save UPLOAD_PATH, False
' Saved file name (without path)
fileName = Upload.Form("file").ShortSaveName
Response.ContentType = "application/json"
Response.write("{""uploadPath"":""/upload/" & fileName & """}")
%>
2. HWP / Word / 엑셀 문서 임포트
주의
아래 샘플 코드의 파일 업로드 부분은 의도적으로 최소화되어 있으며, 적절한 보안 처리가 적용되어 있지 않습니다.
파일 업로드는 프로젝트에 이미 구현된 기능을 사용하고, 아래 코드는 에디터 연동 부분만 참고합니다.
파일 업로드는 TABS Upload5를 사용합니다. 실제 ASP 환경에 통합할 때는 운영 환경에 이미 배포된 파일 업로드 컴포넌트를 사용합니다.
<%@ CodePage=65001 Language=VBScript %>
<% Option Explicit %>
<%
On Error Resume Next
Dim CONVERTER, FONTS, WORK, UPLOAD_PATH
CONVERTER = "C:\workspace\seimporter\sedocConverter\sedocConverter.exe"
FONTS = "C:\workspace\seimporter\fonts"
WORK = "C:\workspace\seimporter\tmp"
UPLOAD_PATH = "C:\inetpub\wwwroot\upload"
Dim filePath, outputPath, uuid, relativeOutputPath
Dim Upload
Set Upload = Server.CreateObject("TABSUpload4.Upload")
Upload.CodePage = 65001
Upload.Start "C:\TEMP"
Upload.Save UPLOAD_PATH, False
filePath = Upload.Form("file").SaveName
uuid = CreateGUID()
outputPath = "C:\inetpub\wwwroot\output\" & uuid
relativeOutputPath = "/output/" & uuid
' Run document conversion
Dim wshShell, strCmd, result
strCmd = CONVERTER & " -pz -f " & FONTS & " """ & filePath & """ " & outputPath & " " & WORK
result = Exec(strCmd, 1)
If Not result = 0 Then
Response.write "Error : " & result
Else
DeleteExistFile(filePath) ' delete original after success
End If
Set wshShell = nothing
Set Upload = Nothing
' Read document.pb, serialize, then delete the .pb file
Dim binText
binText = ReadBinaryFile(outputPath & "\" & "document.pb")
DeleteExistFile(outputPath & "\" & "document.pb")
Response.ContentType = "application/json"
Response.write("{""importPath"":""" & relativeOutputPath & """, ""serializedData"":" & binText & "}")
Function Exec(c, t)
Dim s, e : Set s = CreateObject("WScript.Shell") : Set e = s.Exec(c)
Do While e.Status = 0
Call s.Run("waitfor /t 1 OneSecond", 0, True)
t = t - 1
If 0 >= t Then
Call s.Run("taskkill /t /f /pid " & e.ProcessId, 0, True)
Exit Do
End If
Loop
Set Exec = e
End Function
Function CreateGUID()
Dim tmpTemp
tmpTemp = Right(String(4,48) & Year(Now()),4)
tmpTemp = tmpTemp & Right(String(4,48) & Month(Now()),2)
tmpTemp = tmpTemp & Right(String(4,48) & Day(Now()),2)
tmpTemp = tmpTemp & Right(String(4,48) & Hour(Now()),2)
tmpTemp = tmpTemp & Right(String(4,48) & Minute(Now()),2)
tmpTemp = tmpTemp & Right(String(4,48) & Second(Now()),2)
CreateGUID = tmpTemp
End Function
Function DeleteExistFile(filePath)
Dim fso, result
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(filePath) Then
fso.DeleteFile(filePath)
result = 1
Else
result = 0
End If
DeleteExistFile = result
End Function
Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
Dim bin, str, cnt
BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.Position = 0
BinaryStream.LoadFromFile FileName
cnt = 1
Do
bin = BinaryStream.Read(1024)
if Not isNull(bin) then
if cnt = 1 then
str = str & BinaryToString(bin, 17)
Else
str = str & "," & BinaryToString(bin, 1)
end if
cnt = cnt + 1
end if
Loop While Not IsNull(bin)
ReadBinaryFile = "[" & str & "]"
BinaryStream.Close
Set BinaryStream = Nothing
End Function
Function BinaryToString(Binary, startPosition)
' Optimized binary-to-CSV string for embedding into JSON.
Dim cl1, cl2, cl3, pl1, pl2, pl3, L
cl1 = startPosition
cl2 = 1
cl3 = 1
L = LenB(Binary)
Do While cl1 <= L
pl3 = pl3 & CStr(AscB(MidB(Binary,cl1,1)))
If cl1 < L Then pl3 = pl3 & ","
cl1 = cl1 + 1
cl3 = cl3 + 1
If cl3 > 300 Then
pl2 = pl2 & pl3
pl3 = "" : cl3 = 1 : cl2 = cl2 + 1
If cl2 > 200 Then
pl1 = pl1 & pl2
pl2 = "" : cl2 = 1
End If
End If
Loop
BinaryToString = pl1 & pl2 & pl3
End Function
%>