Here is the method :
`A4D_RequestIsTypeA4D
C_STRING(40;$requestType;$0)
C_LONGINT($1;$streamRef)
$streamRef:=$1
`we'll grab the incoming http header from the stream
C_LONGINT($err)
C_TEXT($headerTxt)
$err:=ITK_TCPRcv
($streamRef;$headerTxt;2000;1;0;<>A4D_CRLF+<>A4D_CRLF;2*60*60)
$err:=ITK_TCPUnRcv ($streamRef;$headerTxt;1) `put header back into the
beginning of the stream
`examine header for info that would indicate a request for an Active4D
file type.
Case of
: (Position("/downloadFile/";$headerTxt)>0)
$requestType:="File Download"
: (Position("/downloadDynamicFile/";$headerTxt)>0)
$requestType:="Dynamic File Download"
: (Position("/Service2/";$headerTxt)>0)
$requestType:="File Download"
Else
$requestType:="A4D"
End case
$0:=$requestType
********************************************************
********************************************************
The other methods called for different requests are below :
********************************************************
********************************************************
` A4D_CGI Server
C_BOOLEAN($0;$requestIsTypeACGI)
C_LONGINT($1;$streamRef;$FileRef;$DocSize)
$requestIsTypeACGI:=False
$streamRef:=$1
$FileRef:=0
READ ONLY(*)
`we'll grab the incoming http header from the stream
C_LONGINT($err)
C_TEXT($headerTxt)
$err:=ITK_TCPRcv
($streamRef;$headerTxt;32000;1;0;<>A4D_CRLF+<>A4D_CRLF;2*60*60)
$start:=Position(" ";$headerTxt)+1
$numChars:=Position("HTTP";$headerTxt)-1-$start
$URL:=Substring($headerTxt;$start;$numChars)
C_TEXT($savedFullURL)
$savedFullURL:=$URL
$pos:=Position("/";$URL)
If ($pos>0)
$delimiter:="/"
Else
$delimiter:="\"
End if
$start:=Position("downloadFile";$URL)
$URL:=Substring($URL;Position("downloadFile";$URL)+13)
C_TEXT($UserIDURL)
$UserIDURL:=$URL
$URL:=Substring($URL;1;Position($delimiter;$URL)-1)
C_BLOB($Response)
$tableNumber:=Num(Substring($URL;1;3))
$fileID:=Num(Substring($URL;4;14)) ` padded to 14 characters - will
eventually be a keyfield
$fileToGet:=Substring($URL;18;2)
C_LONGINT($UserID_l)
` Get User ID from URL
$pos:=Position("CID";$UserIDURL)
If ($pos>1)
$UserID_l:=Num(Substring($UserIDURL;$pos+3;11))
End if
C_LONGINT($PrivilegeError)
$PrivilegeError:=-1
If ($UserID_l>0)
C_STRING(14;$dtstamp)
` within 1 hour past
$dtstamp:=rpl_DateTimeStamp (Current date;Time(Time string(Current
time-3600)))
QUERY([Utility_INT];[Utility_INT]RecordType="Web Page Request";*)
QUERY([Utility_INT]; & ;[Utility_INT]LongInt1=$UserID_l;*)
QUERY([Utility_INT]; & ;[Utility_INT]DateTimeStamp>=$dtstamp)
If (Records in selection([Utility_INT])>0)
$PrivilegeError:=0
Else
$PrivilegeError:=-1
End if
End if
If ($PrivilegeError=0) ` no error.
C_BLOB($fullResponse)
TEXT TO BLOB("HTTP/1.0 200 OK"+<>A4D_CRLF;$fullResponse;Text without
length ;*)
TEXT TO BLOB("Cache-Control:no-cache"+<>A4D_CRLF;$fullResponse;Text
without length ;*)
TEXT TO BLOB("Pragma:no-cache"+<>A4D_CRLF;$fullResponse;Text without
length ;*)
TEXT TO BLOB("Expires:"+ITK_Secs2RFC (ITK_Date2Secs (Current date;Current
time;1);1)+<>A4D_CRLF;$fullResponse;Text without length ;*)
C_STRING(31;fileName_s31)
C_TEXT($filePath)
If ($tableNumber=44) ` archived File List
QUERY([Preview_In_Folders_INT];[Preview_In_Folders_INT]File_ID=$fileID;*)
QUERY([Preview_In_Folders_INT]; &
;[Preview_In_Folders_INT]TableNumber=$tableNumber;*)
QUERY([Preview_In_Folders_INT]; &
;[Preview_In_Folders_INT]Preview_Order=0)
If (Records in selection([Preview_In_Folders_INT])=1)
$filePath:=[Preview_In_Folders_INT]Path_To_Preview+Preview_Name+"_h.pdf"
Else
$filePath:=PREV_GetOriginalPath ($tableNumber;$fileID;->fileName_s31)
End if
Else
$filePath:=PREV_GetOriginalPath ($tableNumber;$fileID;->fileName_s31)
End if
If ($filePath#"")
Case of
: ($fileToGet="HH")
` do nothing for Hi-Res files (just send)
: ($fileToGet="LR")
If ($tableNumber=Table(->[LibraryFiles_FM]))
QUERY([LibraryFiles_FM];[LibraryFiles_FM]File_ID=$fileID)
If (Records in selection([LibraryFiles_FM])>0)
QUERY([Libraries_FM];[Libraries_FM]Library_ID=[LibraryFiles_FM]Library_ID)
If (Records in selection([Libraries_FM])>0)
If ([Libraries_FM]LoResPath#"")
C_TEXT($rootPath)
$rootPath:=""
QUERY([LibraryFolders_FM];[LibraryFolders_FM]LibraryFolderID=[Libraries_FM]L
ibrary_ID)
If ([Libraries_FM]VolumeIsRoot=False)
$rootPath:=[Libraries_FM]LibraryRootPath+[LibraryFolders_FM]FolderName
Else
$rootPath:=[Libraries_FM]LibraryRootPath
End if
$filePath:=Replace
string($filePath;$rootPath;[Libraries_FM]LoResPath;1)
Else
$filePath:=""
End if
End if
End if
End if
End case
If ($filePath#"") ` if no path then set failure
`$ret:=LDR_DocumentToBLOB ($filePath;$Response)
$FileRef:=LDR_OpenFile ($filePath;2)
$DocSize:=LDR_FileSize ($FileRef)
Else
$FileRef:=-1
End if
If ($FileRef>0)
TEXT TO BLOB("Content-Length:"+String(0)+<>A4D_CRLF;$fullResponse;Text
without length ;*)
TEXT TO
BLOB("Content-Type:application/octet-stream"+<>A4D_CRLF;$fullResponse;Text
without length ;*)
Else
TEXT TO BLOB("Sorry, unable to load asset.";$Response;Text without
length ;*)
TEXT TO BLOB("Content-Length:"+String(BLOB
size($Response))+<>A4D_CRLF;$fullResponse;Text without length ;*)
TEXT TO BLOB("Content-Type:text/plain"+<>A4D_CRLF;$fullResponse;Text
without length ;*)
End if
Else ` URL or privilege error.
TEXT TO BLOB("Sorry, unable to load asset.";$Response;Text without
length ;*)
TEXT TO BLOB("Content-Length:"+String(BLOB
size($Response))+<>A4D_CRLF;$fullResponse;Text without length ;*)
TEXT TO BLOB("Content-Type:text/plain"+<>A4D_CRLF;$fullResponse;Text
without length ;*)
End if
`We need one extra CRLF to separate the headers from the body
TEXT TO BLOB(<>A4D_CRLF;$fullResponse;Text without length ;*)
$err:=ITK_TCPSendBlob ($streamRef;$fullResponse)
If ($FileRef>0)
C_BLOB(a4d_tmpBlob)
C_LONGINT($maxSize)
$maxSize:=(1024*1024)
Repeat
$bytesRead:=LDR_ReadFile ($FileRef;a4d_tmpBlob;$maxSize)
$err:=ITK_TCPSendBlob ($streamRef;a4d_tmpBlob)
SET BLOB SIZE(a4d_tmpBlob;0)
Until (($bytesRead#$maxSize) | ($err#0))
$err:=LDR_CloseFile ($FileRef)
Else
$err:=ITK_TCPSendBlob ($streamRef;$Response)
End if
If (($err=0) & ($FileRef>0)) ` success
CREATE RECORD([Utility_INT])
[Utility_INT]Utility_ID:=Sequence number([Utility_INT])
[Utility_INT]RecordType:="Web Image Download"
[Utility_INT]Text1:=$savedFullURL+Char(13)+Char(13)+"on "+String(Current
date)+" - "+String(Current time)
[Utility_INT]LongInt1:=$userID_l
[Utility_INT]LongInt2:=$fileID
[Utility_INT]LongInt3:=$tableNumber
[Utility_INT]Date1:=Current date
QUERY([Contact_Names_BASE];[Contact_Names_BASE]Contact_ID=$userID_l)
QUERY([Customers_BASE];[Customers_BASE]Cust_ID=[Contact_Names_BASE]Cust_ID)
Case of
: ($tableNumber=97)
QUERY([LibraryFiles_FM];[LibraryFiles_FM]File_ID=$fileID)
[Utility_INT]Alpha40:=[LibraryFiles_FM]FileName
[Utility_INT]Alpha20:="Library Element"
[Utility_INT]Real1:=Round([LibraryFiles_FM]FileSize/1048576;2)
: ($tableNumber=44)
QUERY([Archived_File_List_BASE];[Archived_File_List_BASE]File_ID=$fileID)
QUERY([Jobs_BASE];[Jobs_BASE]Job_ID=[Archived_File_List_BASE]Job_ID)
[Utility_INT]Alpha40:=[Archived_File_List_BASE]File_Name
[Utility_INT]Alpha20:=[Jobs_BASE]CustJobNo
[Utility_INT]Real1:=Round([Archived_File_List_BASE]Archived_File_Size;2)
: ($tableNumber=36)
QUERY([WIP_FM];[WIP_FM]File_ID=$fileID)
QUERY([Jobs_BASE];[Jobs_BASE]Job_ID=[WIP_FM]Job_ID)
[Utility_INT]Alpha40:=[WIP_FM]FileName
[Utility_INT]Alpha20:=[Jobs_BASE]CustJobNo
[Utility_INT]Real1:=Round([WIP_FM]FileSize;2)
End case
[Utility_INT]Text2:=[Contact_Names_BASE]NameConcat
SAVE RECORD([Utility_INT])
End if
Else ` NO Current session for user or user ID invalid
C_BLOB($fullResponse;$Response)
TEXT TO BLOB("HTTP/1.0 200 OK"+<>A4D_CRLF;$fullResponse;Text without
length ;*)
TEXT TO BLOB("Cache-Control:no-cache"+<>A4D_CRLF;$fullResponse;Text
without length ;*)
TEXT TO BLOB("Pragma:no-cache"+<>A4D_CRLF;$fullResponse;Text without
length ;*)
TEXT TO BLOB("Expires:"+ITK_Secs2RFC (ITK_Date2Secs (Current date;Current
time;1);1)+<>A4D_CRLF;$fullResponse;Text without length ;*)
TEXT TO BLOB("Sorry, unable to load asset.";$Response;Text without length
;*)
TEXT TO BLOB("Content-Length:"+String(BLOB
size($Response))+<>A4D_CRLF;$fullResponse;Text without length ;*)
TEXT TO BLOB("Content-Type:text/plain"+<>A4D_CRLF;$fullResponse;Text
without length ;*)
TEXT TO BLOB(<>A4D_CRLF;$fullResponse;Text without length ;*)
$err:=ITK_TCPSendBlob ($streamRef;$fullResponse)
$err:=ITK_TCPSendBlob ($streamRef;$Response)
End if
********************************************************
********************************************************