project BLF > class TDocumentLink > method CreateResource
Parameters
icCollection | input | character | |
icResource | input | character | |
icFileName | input | character | use file name when the data to send to webdav is stored on the file system |
imFileContent | input | memptr | use file content in case the data to send to webdav is stored in memory |
ocResponse | output | character | |
Internal usage
BLF
program code (program1/tdocumentlink.p)
<M-70 run CollectionExists
(input vcWebdavRoot + icCollection (icPath),
output vlExists (olExists)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
if vlExists = no
then do:
vcPath = vcWebdavRoot.
do viC1 = 1 to num-entries(icCollection,"/") - 1:
vcPath = vcPath + entry(viC1,icCollection,"/") + "/".
<M-36 run CollectionExists
(input vcPath (icPath),
output vlExists (olExists)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
if vlExists = no
then do:
<M-72 run CreateCollection (input vcPath (icPath)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
end.
end.
<M-95 run CreateCollection (input vcWebdavRoot + iccollection (icPath)) in TDocumentLink>
if vcWebdavResponse <> ""
then return.
end.
if icFileName = ""
then do:
vcommand = "PUT " + vcWebdavRoot + icCollection + "/" + icResource + " HTTP/1.0"
+ "~nContent-Length: " + string(get-size(imFileContent)) + "~n~n".
set-size(vmSend) = length(vcommand,"RAW") + get-size(imFileContent) + 1.
put-string(vmSend,1) = vcommand.
put-bytes(vmSend,length(vcommand,"RAW") + 1) = imFileContent.
end.
else do:
copy-lob from file icFileName to vmFile.
vcommand = "PUT " + vcWebdavRoot + icCollection + "/" + icResource + " HTTP/1.0"
+ "~nContent-Length: " + string(get-size(vmFile)) + "~n~n".
set-size(vmSend) = length(vcommand,"RAW") + get-size(vmFile) + 1.
put-string(vmSend,1) = vcommand.
put-bytes(vmSend,length(vcommand,"RAW") + 1) = vmFile.
end.
<M-78 run Connect () in TDocumentLink>
if vcWebdavResponse <> ""
then return.
vhWebdavSocket:write (vmSend,1,get-size(vmSend)).
wait-for read-response of vhWebdavSocket pause 60.
if index (vcWebdavResponse," 201 ") > 0 /* CREATED */
or index (vcWebdavResponse," 204 ") > 0 /* REPLACED */
then vcWebdavResponse = "".
finally:
set-size (vmSend) = 0.
set-size (vmFile) = 0.
if vhWebdavSocket <> ?
then do:
vhWebdavSocket:disconnect ().
delete object vhWebdavSocket.
vhWebdavSocket = ?.
end.
ocResponse = vcWebdavResponse.
end finally.