Using Powershell and CSOM, on Sharepoint Online, I have successfully upoaded 300K pdf files w/metadata into folders in document libraries.
Today, though, the same code is failing to Add files...
Snippets of code follow:
#Get File Collection for folder
$Files = $folder.Files
$context.Load($Files)
$context.ExecuteQuery()
try
{
# Setup FileStream and FileInfo
$FileStream = New-Object IO.FileStream($SrcFilePath,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $folderUrl + '/' + $_.SedaID
# Upload FIle
$Upload = $Files.Add($FileCreationInfo)
$context.Load($Upload)
$context.Load($Upload.ListItemAllFields)
$context.ExecuteQuery()
# Update Metadata
Set-SPOListItem -List $listTitle -Identity $($Upload.ListItemAllFields.Id) `
-ContentType "SEDA Document" -Values $Metadata
}
Catch
{
$ErrorMessage = $_.Exception.Message
$ItemFailed = $true
$FailCount += 1
“$Time : Error Uploading {0}:`t {1}" -f $_.SedaID, $ErrorMessage | out-file $ErrorFile -append
}
$Filestream appears legit:
$FileCreationInfo appears legit:
But folder.Files.Add(FileCreationInfo) now Errors like this:
Any idea what I am doing wrong this time?