Hi
Here are the two functions used to Checkin and Upload files to Vault. Let me know if you are able to reproduce the problem by calling the CheckinFile function in VDS.
Regards,
Cassidy
Function UploadFile {
param (
[System.Object[]] $vault = $(throw "-vault is required."),
[string]$filePath = $(throw "-filename is required.")
)
if(-Not (Test-Path $filePath -PathType Leaf)) {
Exit
}
$maxFilePartSize = 49 * 1024 * 1024 # 49MB perchunk
$fileContents = [System.IO.File]::ReadAllBytes($filePath)
# ---------------------------------------------------------------------------------------------------------------
$vault.FilestoreService.FileTransferHeaderValue = New-Object Autodesk.Connectivity.WebServices.FileTransferHeader
$vault.FilestoreService.FileTransferHeaderValue.Identity = [Guid]::NewGuid()
$vault.FilestoreService.FileTransferHeaderValue.Extension = [System.IO.Path]::GetExtension($filePath)
$vault.FilestoreService.FileTransferHeaderValue.Vault = $vault.WebServiceCredentials.VaultName
# create a upload ticket, this is a prerequisiste for checking the file out
$uploadTicket = New-Object Autodesk.Connectivity.WebServices.ByteArray
$bytesSent = 0
$bufferSize = $maxFilePartSize
while ($bytesSent -lt $fileContents.Length) {
if (($fileContents.Length - $bytesSent) -lt $maxFilePartSize) {
$bufferSize = $fileContents.Length - $bytesSent
}
else {
$bufferSize = $maxFilePartSize
}
$Compression = New-Object Autodesk.Connectivity.WebServices.Compression
$vault.FilestoreService.FileTransferHeaderValue.Compression = $Compression::None
$vault.FilestoreService.FileTransferHeaderValue.UncompressedSize = $bufferSize
if (($bufferSize + $bytesSent) -ge $fileContents.Length) {
$isComplete = $true
}
else {
$isComplete = $false
}
$vault.FilestoreService.FileTransferHeaderValue.IsComplete = $isComplete
[byte[]] $buffer = $null
if ($bufferSize -eq $fileContents.Length) {
$buffer = $fileContents
}
else {
$buffer = New-Object byte[] $bufferSize
[System.Array] $Array.Copy($fileContents,[long] $bytesSent, $buffer, 0, [long] $bufferSize)
}
$bufferStream = New-Object System.IO.MemoryStream(,$buffer)
$uploadTicket.Bytes = $vault.FilestoreService.UploadFilePart($bufferStream)
$bytesSent += $bufferSize
}
return $uploadTicket
}
Function ChkinFile {
param (
[System.Object[]] $vaultConnection = $(throw "-vaultConnection is required."),
[string]$filePath = $(throw "-filePath is required."),
[string]$comment = $(throw "-comment is required.")
)
# Get WebServiceManager object
$vault = $vaultConnection.WebServiceManager
# Get vault root folder
$root = $vault.DocumentService.GetFolderRoot();
# Get vault working folder (C:\TEMP\Vault\)
$workingFolder = $vaultConnection.WorkingFoldersManager.GetWorkingFolder($root.FullName).FullPath
# Get vault folder path
$vltFilePath = $filePath.Replace($workingFolder,"$/").Replace('\','/')
# Get file object from vault file path
$file = $vault.DocumentService.FindLatestFilesByPaths($vltFilePath)
# get child file associations so we can preserve them.
$FileAssocAlg = New-Object Autodesk.Connectivity.WebServices.FileAssocAlg
$FileAssociationTypeEnum = New-Object Autodesk.Connectivity.WebServices.FileAssociationTypeEnum
[Autodesk.Connectivity.WebServices.FileAssocLite[]] $childAssocs = $vault.DocumentService.GetFileAssociationLitesByIds($file.Id, $FileAssocAlg::Actual.value__, $FileAssociationTypeEnum::None.value__, $false, $FileAssociationTypeEnum::All.value__, $false, $true, $false, $true)
# convert FileAssocLite array to FileAssocParam array
$associations = @()
foreach ($childAssoc in $childAssocs)
{
$childAssocObj = New-Object Autodesk.Connectivity.WebServices.FileAssocParam -Property @{ Typ = $childAssoc.Typ; CldFileId = $childAssoc.CldFileId; Source = $childAssoc.Source; RefId = $childAssoc.RefId; ExpectedVaultPath = $childAssoc.ExpectedVaultPath }
if ($null -ne $childAssocObj)
{
$associations += $childAssocObj
}
}
# upload/checkin pdf drawing file from local to Vault
# create a ticket to check the file back in with
$uploadTicket = UploadFile -vault $vault -filePath $filePath
# check the file back in
$checkedInFile = $vault.DocumentService.CheckinUploadedFile($file.MasterId, $comment, $false, `
(Get-Date),$associations,$null,$true,$file.Name,$file.FileClass,$file.Hidden,$uploadTicket)
return $checkedInFile
}