10

I am tring to upload large files (900 MB) to SP Online (actually the OneDrive Business) but seems to follow SP style.

Tried this via CSOM and powershell 70 MB are fine but when I try 900 MB a timeout happens after 3min

Error :

Exception calling "ExecuteQuery" with "0" argument(s): "The operation has timed out" At C:\scripts\BackupToCloud\BackupToCloud1.ps1:89 char:1 + $ctx.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException

My upload part (of the script):

Foreach ($File in (dir $LocalBckupFolder))
{
    $StartAFile = get-date -uformat "%Y-%m-%d %H:%M:%S"
    Add-Content $log "$StartAFile :: Start Upload file: $File.name"
    $FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
    $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
    $FileCreationInfo.Overwrite = $true
    $FileCreationInfo.ContentStream = $FileStream
    $FileCreationInfo.URL = $File
    $Upload = $SPfolder.Files.Add($FileCreationInfo)
    $ctx.Load($Upload)
    $ctx.ExecuteQuery()
    $FinishAFile = get-date -uformat "%Y-%m-%d %H:%M:%S"
    Add-Content $log "$FinishAFile :: Done Upload file: $File.name"
}

$ctx.Dispose()

Try to use $ctx.RequestTimeout = = 3600000; or $ctx.RequestTimeout = int.MaxValue; but this is not recognized. As SharePoint Online doesn't offer the Get-SPWebApplication I can't set timeout there as I could on premise (no Get-SPOWebApplication available).

Also if large file upload via powershell to O365 (SP or OneDrive) should be done differently I'm open for suggestions.

1

4 Answers 4

1

Please see an example below:

$username = "[email protected]" 
$password = "Password" 
$url = "https://domain.sharepoint.com/sites/Test"
$path = "C:\temp\test";
$destination = $url + "/Shared Documents"; #lib partial url

$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force 

# the path here may need to change if you used e.g. C:\Lib.. 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

# connect/authenticate to SharePoint Online and get ClientContext object.. 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword) 

$webclient = New-Object System.Net.WebClient;
$webclient.Headers["Cookie"] = $credentials.GetAuthenticationCookie($url)

Get-ChildItem $path | Where-Object {$_.Length -gt 0} | ForEach-Object { 
    $webclient.UploadFile($destination + "/" + $_.Name, "PUT", $_.FullName); 
};

I have used PUT method to upload files

1
  • Does this work for large files? And do you see any issue with converting this to C# to use in a Provider-hosted app?
    – wjervis
    Feb 10, 2016 at 16:24
1

Check this out it will help you Large file upload in SharePoint Online with CSOM PowerShell

0
0

If you could try writing a console application with CSOM, this could be achieved. Please refer to the Office Dev PnP link.

PS: Sorry I am not sure about powershell.

-6

Find a different solution for files of that size, SharePoint cannot handle them.

13
  • The technical upper bound to file sizes is 2GB, SharePoint can handle them, but it might not be configured to accept files that large. Jul 23, 2014 at 15:44
  • 2 GB is the limit of OneDrive Business and SP online (office.microsoft.com/en-ca/…) "File upload limit 2 GB per file."
    – Tilo
    Jul 23, 2014 at 15:58
  • Technical limit and reality limit are two different things in this case. SharePoint is not designed to handle files of that size, use a different solution.
    – Aboba
    Jul 23, 2014 at 15:59
  • Is OneDrive business designed to handle large files? Also how large is too large? What is your suggestion? 50 MB, 100MB ???
    – Tilo
    Jul 23, 2014 at 16:01
  • 200MB is the maximum I will use for storing a file in SharePoint, after that there are just too many technical issues for it to be the best system.
    – Aboba
    Jul 23, 2014 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.