Google API Client Library for .NET  1.10.0
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | Events | List of all members
Google.Apis.Upload.ResumableUpload< TRequest > Class Template Reference

Media upload which uses Google's resumable media upload protocol to upload data. More...

Inheritance diagram for Google.Apis.Upload.ResumableUpload< TRequest >:
Google.Apis.Upload.ResumableUpload< TRequest, TResponse >

Public Member Functions

IUploadProgress GetProgress ()
 Get the current progress state. More...
 
IUploadProgress Upload ()
 Uploads the content to the server. This method is synchronous and will block until the upload is completed. More...
 
Task< IUploadProgressUploadAsync ()
 Uploads the content asynchronously to the server. More...
 
async Task< IUploadProgressUploadAsync (CancellationToken cancellationToken)
 Uploads the content to the server using the given cancellation token. More...
 
IUploadProgress Resume ()
 Resumes the upload form the last point it was interrupted. More...
 
Task< IUploadProgressResumeAsync ()
 Asynchronously resumes the upload form the last point it was interrupted. More...
 
async Task< IUploadProgressResumeAsync (CancellationToken cancellationToken)
 Asynchronously resumes the upload form the last point it was interrupted. More...
 

Public Attributes

const int MinimumChunkSize = 256 * KB
 Minimum chunk size (except the last one). Default value is 256*KB. More...
 
const int DefaultChunkSize = 10 * MB
 Default chunk size. Default value is 10*MB. More...
 

Protected Member Functions

 ResumableUpload (IClientService service, string path, string httpMethod, Stream contentStream, string contentType)
 Create a resumable upload instance with the required parameters. More...
 
virtual void ProcessResponse (HttpResponseMessage httpResponse)
 Process a response from the final upload chunk call. More...
 
async Task< bool > SendNextChunkAsync (Stream stream, CancellationToken cancellationToken)
 Uploads the next chunk of data to the server. More...
 

Protected Attributes

int chunkSize = DefaultChunkSize
 Change this value ONLY for testing purposes! More...
 

Properties

IClientService Service [get, set]
 Gets or sets the service. More...
 
string Path [get, set]
 Gets or sets the path of the method (combined with Google.Apis.Services.IClientService.BaseUri) to produce absolute Uri. More...
 
string HttpMethod [get, set]
 Gets or sets the HTTP method of this upload (used to initialize the upload). More...
 
Stream ContentStream [get, set]
 Gets or sets the stream to upload. More...
 
string ContentType [get, set]
 Gets or sets the stream's Content-Type. More...
 
TRequest Body [get, set]
 Gets or sets the body of this request. More...
 
int ChunkSize [get, set]
 Gets or sets the size of each chunk sent to the server. Chunks (except the last chunk) must be a multiple of MinimumChunkSize to be compatible with Google upload servers. More...
 

Events

Action< IUploadProgressProgressChanged
 Event called whenever the progress of the upload changes. More...
 

Detailed Description

Media upload which uses Google's resumable media upload protocol to upload data.

See: https://developers.google.com/drive/manage-uploads#resumable for more information on the protocol.

Template Parameters
TRequestThe type of the body of this request. Generally this should be the metadata related to the content to be uploaded. Must be serializable to/from JSON.

Constructor & Destructor Documentation

Google.Apis.Upload.ResumableUpload< TRequest >.ResumableUpload ( IClientService  service,
string  path,
string  httpMethod,
Stream  contentStream,
string  contentType 
)
inlineprotected

Create a resumable upload instance with the required parameters.

Parameters
serviceThe client service.
pathThe path for this media upload method.
httpMethodThe HTTP method to start this upload.
contentStreamThe stream containing the content to upload.
contentTypeContent type of the content to be uploaded.

Caller is responsible for maintaining the contentStream open until the upload is completed. Caller is responsible for closing the contentStream .

Member Function Documentation

IUploadProgress Google.Apis.Upload.ResumableUpload< TRequest >.GetProgress ( )
inline

Get the current progress state.

Returns
An IUploadProgress describing the current progress of the upload.
See Also
ProgressChanged
virtual void Google.Apis.Upload.ResumableUpload< TRequest >.ProcessResponse ( HttpResponseMessage  httpResponse)
inlineprotectedvirtual

Process a response from the final upload chunk call.

Parameters
httpResponseThe response body from the final uploaded chunk.

Reimplemented in Google.Apis.Upload.ResumableUpload< TRequest, TResponse >.

IUploadProgress Google.Apis.Upload.ResumableUpload< TRequest >.Resume ( )
inline

Resumes the upload form the last point it was interrupted.

Task<IUploadProgress> Google.Apis.Upload.ResumableUpload< TRequest >.ResumeAsync ( )
inline

Asynchronously resumes the upload form the last point it was interrupted.

async Task<IUploadProgress> Google.Apis.Upload.ResumableUpload< TRequest >.ResumeAsync ( CancellationToken  cancellationToken)
inline

Asynchronously resumes the upload form the last point it was interrupted.

Parameters
cancellationTokenA cancellation token to cancel operation.
async Task<bool> Google.Apis.Upload.ResumableUpload< TRequest >.SendNextChunkAsync ( Stream  stream,
CancellationToken  cancellationToken 
)
inlineprotected

Uploads the next chunk of data to the server.

Returns
True if the entire media has been completely uploaded.
IUploadProgress Google.Apis.Upload.ResumableUpload< TRequest >.Upload ( )
inline

Uploads the content to the server. This method is synchronous and will block until the upload is completed.

In case the upload fails the IUploadProgress.Exception will contain the exception that cause the failure.

Task<IUploadProgress> Google.Apis.Upload.ResumableUpload< TRequest >.UploadAsync ( )
inline

Uploads the content asynchronously to the server.

async Task<IUploadProgress> Google.Apis.Upload.ResumableUpload< TRequest >.UploadAsync ( CancellationToken  cancellationToken)
inline

Uploads the content to the server using the given cancellation token.

In case the upload fails IUploadProgress.Exception will contain the exception that cause the failure. The only exception which will be thrown is System.Threading.Tasks.TaskCanceledException which indicates that the task was canceled.

Parameters
cancellationTokenA cancellation token to cancel operation.

Member Data Documentation

int Google.Apis.Upload.ResumableUpload< TRequest >.chunkSize = DefaultChunkSize
protected

Change this value ONLY for testing purposes!

const int Google.Apis.Upload.ResumableUpload< TRequest >.DefaultChunkSize = 10 * MB

Default chunk size. Default value is 10*MB.

const int Google.Apis.Upload.ResumableUpload< TRequest >.MinimumChunkSize = 256 * KB

Minimum chunk size (except the last one). Default value is 256*KB.

Property Documentation

TRequest Google.Apis.Upload.ResumableUpload< TRequest >.Body
getset

Gets or sets the body of this request.

int Google.Apis.Upload.ResumableUpload< TRequest >.ChunkSize
getset

Gets or sets the size of each chunk sent to the server. Chunks (except the last chunk) must be a multiple of MinimumChunkSize to be compatible with Google upload servers.

Stream Google.Apis.Upload.ResumableUpload< TRequest >.ContentStream
getset

Gets or sets the stream to upload.

string Google.Apis.Upload.ResumableUpload< TRequest >.ContentType
getset

Gets or sets the stream's Content-Type.

string Google.Apis.Upload.ResumableUpload< TRequest >.HttpMethod
getset

Gets or sets the HTTP method of this upload (used to initialize the upload).

string Google.Apis.Upload.ResumableUpload< TRequest >.Path
getset

Gets or sets the path of the method (combined with Google.Apis.Services.IClientService.BaseUri) to produce absolute Uri.

IClientService Google.Apis.Upload.ResumableUpload< TRequest >.Service
getset

Gets or sets the service.

Event Documentation

Action<IUploadProgress> Google.Apis.Upload.ResumableUpload< TRequest >.ProgressChanged

Event called whenever the progress of the upload changes.


The documentation for this class was generated from the following file: