pnpcore icon indicating copy to clipboard operation
pnpcore copied to clipboard

Downloading large files 2 issues

Open alexeygritsenko opened this issue 2 years ago • 3 comments

The default HTTP timeout is 100 seconds,

  1. If the timeout is reached while loading the file, no exception or error will be thrown. Simply downloading the file will remain incomplete or defective. Expected behavior: When the timeout is reached, an exception should be thrown.

  2. If you use GetPnPContextAsync, then the timeout cannot be set or inheritance from ClientRuntimeContext.RequestTimeout does not work. Expected behavior: Timeout must be set by their ClientRuntimeContext.RequestTimeout or be able to configure.

example: I am using pnp in .net framework 4.8 project with classic Microsoft.SharePoint.Client.ClientContext only in the download location

var clientContext = //crete classic client context
clientContext.RequestTimeout = 1800000; //30 minutes

using (var pnpCoreContext = await PnPCoreSdk.Instance.GetPnPContextAsync(clientContext))
{
	IFile targetFile = await pnpCoreContext.Web.GetFileByServerRelativeUrlAsync(fileRef);
	var stream = await targetFile.GetContentAsync(true);
	//stream read by chunk code
}

alexeygritsenko avatar Sep 19 '22 11:09 alexeygritsenko

@alexeygritsenko : PnP Core SDK does have an option to set the timeout (see https://pnp.github.io/pnpcore/using-the-sdk/basics-settings.html#settings-overview and https://pnp.github.io/pnpcore/using-the-sdk/files-large.html). It's however not possible to set this at the CSOM ClientContext and then use it in PnP Core SDK. If you directly instantiate the PnP Context and use the configuration setting, then things will work.

This however raises an interesting point on how to plug-in configuration settings when PnP Core SDK is instantiated via PnP Framework, guess some updates are needed in https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/PnPCoreSdk.cs#L83-L129

jansenbe avatar Sep 19 '22 14:09 jansenbe

This however raises an interesting point on how to plug-in configuration settings when PnP Core SDK is instantiated via PnP Framework, guess some updates are needed in https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/PnPCoreSdk.cs#L83-L129 👍

And as for point 1 (timeout triggering), it looks like this behavior HttpClient. When I download a file and read it in parts of 8 MB (buffer), even for a long time (7 minutes), there are no connection problems (with a 100 sec default timeout).

alexeygritsenko avatar Sep 20 '22 12:09 alexeygritsenko

@alexeygritsenko : so you're unblocked at the moment?

jansenbe avatar Sep 20 '22 13:09 jansenbe

@alexeygritsenko : tracking the need to set configuration from PnP Framework in #987. Closing this issue now.

jansenbe avatar Oct 13 '22 10:10 jansenbe