public
abstract
class
ResumableUpload
Media upload which uses Google's resumable media upload protocol to upload data.
Derived Types
Namespace
Google.Apis.UploadAssembly
Google.Apis.dll
Remarks
See: https://developers.google.com/drive/manage-uploads#resumable for more information on the protocol.
Constructors
ResumableUpload(Stream, ResumableUploadOptions)
protected
ResumableUpload
(
Stream
contentStream
,
ResumableUploadOptions
options
)
Creates a ResumableUpload instance.
contentStream
options
Fields
DefaultChunkSize
public
const
int
DefaultChunkSize
=
10485760
Default chunk size. Default value is 10*MB.
MinimumChunkSize
public
const
int
MinimumChunkSize
=
262144
Minimum chunk size (except the last one). Default value is 256*KB.
chunkSize
protected int chunkSize
Change this value ONLY for testing purposes!
Properties
ChunkSize
public 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.
ContentStream
public Stream ContentStream { get; }
Gets or sets the stream to upload.
Options
protected
ResumableUploadOptions
Options
{
get
;
}
Gets the options used to control the resumable upload.
UploadStreamInterceptor
public
StreamInterceptor
UploadStreamInterceptor
{
get
;
set
;
}
Interceptor used to propagate data successfully uploaded on each chunk.
Methods
CreateFromUploadUri(Uri, Stream, ResumableUploadOptions)
public
static
ResumableUpload
CreateFromUploadUri
(
Uri
uploadUri
,
Stream
contentStream
,
ResumableUploadOptions
options
=
null
)
Creates a ResumableUpload instance for a resumable upload session which has already been initiated.
uploadUri
contentStream
options
The instance which can be used to upload the specified content.
See https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload#start-resumable for more information about initiating resumable upload sessions and saving the session URI, or upload URI.
ExceptionForResponseAsync(HttpResponseMessage)
protected Task<GoogleApiException> ExceptionForResponseAsync(HttpResponseMessage response)
Creates a GoogleApiException instance using the error response from the server.
GetProgress()
public
IUploadProgress
GetProgress
()
Get the current progress state.
An IUploadProgress describing the current progress of the upload.
InitiateSessionAsync(CancellationToken)
public abstract Task<Uri> InitiateSessionAsync(CancellationToken cancellationToken = default)
Initiates the resumable upload session and returns the session URI, or upload URI. See https://developers.google.com/drive/manage-uploads#start-resumable and https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload#start-resumable for more information.
cancellationToken
ProcessResponse(HttpResponseMessage)
protected virtual void ProcessResponse(HttpResponseMessage httpResponse)
Process a response from the final upload chunk call.
httpResponse
Resume()
public
IUploadProgress
Resume
()
Resumes the upload from the last point it was interrupted. Use when resuming and the program was not restarted.
Resume(Uri)
public
IUploadProgress
Resume
(
Uri
uploadUri
)
Resumes the upload from the last point it was interrupted. Use when the program was restarted and you wish to resume the upload that was in progress when the program was halted. Implemented only for ContentStreams where .CanSeek is True.
uploadUri
Uri
VideosResource.InsertMediaUpload UploadUri property value that was saved to persistent storage during a prior execution.
In your application's UploadSessionData Event Handler, store UploadUri.AbsoluteUri property value (resumable session URI string value) to persistent storage for use with Resume() or ResumeAsync() upon a program restart. It is strongly recommended that the FullPathFilename of the media file that is being uploaded is saved also so that a subsequent execution of the program can compare the saved FullPathFilename value to the FullPathFilename of the media file that it has opened for uploading. You do not need to seek to restart point in the ContentStream file.
ResumeAsync()
public
Task<IUploadProgress>
ResumeAsync
()
Asynchronously resumes the upload from the last point it was interrupted.
You do not need to seek to restart point in the ContentStream file.
ResumeAsync(CancellationToken)
public
Task<IUploadProgress>
ResumeAsync
(
CancellationToken
cancellationToken
)
Asynchronously resumes the upload from the last point it was interrupted. Use when resuming and the program was not restarted.
cancellationToken
You do not need to seek to restart point in the ContentStream file.
ResumeAsync(Uri)
public
Task<IUploadProgress>
ResumeAsync
(
Uri
uploadUri
)
Asynchronously resumes the upload from the last point it was interrupted. Use when resuming and the program was restarted. Implemented only for ContentStreams where .CanSeek is True.
uploadUri
Uri
VideosResource.InsertMediaUpload UploadUri property value that was saved to persistent storage during a prior execution.
In your application's UploadSessionData Event Handler, store UploadUri.AbsoluteUri property value (resumable session URI string value) to persistent storage for use with Resume() or ResumeAsync() upon a program restart. It is strongly recommended that the FullPathFilename of the media file that is being uploaded is saved also so that a subsequent execution of the program can compare the saved FullPathFilename value to the FullPathFilename of the media file that it has opened for uploading. You do not need to seek to restart point in the ContentStream file.
ResumeAsync(Uri, CancellationToken)
public
Task<IUploadProgress>
ResumeAsync
(
Uri
uploadUri
,
CancellationToken
cancellationToken
)
Asynchronously resumes the upload from the last point it was interrupted. Use when the program was restarted and you wish to resume the upload that was in progress when the program was halted. Implemented only for ContentStreams where .CanSeek is True.
uploadUri
Uri
VideosResource.InsertMediaUpload UploadUri property value that was saved to persistent storage during a prior execution.
cancellationToken
In your application's UploadSessionData Event Handler, store UploadUri.AbsoluteUri property value (resumable session URI string value) to persistent storage for use with Resume() or ResumeAsync() upon a program restart. It is strongly recommended that the FullPathFilename of the media file that is being uploaded is saved also so that a subsequent execution of the program can compare the saved FullPathFilename value to the FullPathFilename of the media file that it has opened for uploading. You do not need to seek to restart point in the ContentStream file.
SendNextChunkAsync(Stream, CancellationToken)
protected Task<bool> SendNextChunkAsync(Stream stream, CancellationToken cancellationToken)
Uploads the next chunk of data to the server.
Upload()
public
IUploadProgress
Upload
()
Uploads the content to the server. This method is synchronous and will block until the upload is completed.
In case the upload fails the Exception will contain the exception that cause the failure.
UploadAsync()
public
Task<IUploadProgress>
UploadAsync
()
Uploads the content asynchronously to the server.
UploadAsync(CancellationToken)
public
Task<IUploadProgress>
UploadAsync
(
CancellationToken
cancellationToken
)
Uploads the content to the server using the given cancellation token.
cancellationToken
In case the upload fails Exception will contain the exception that cause the failure. The only exception which will be thrown is TaskCanceledException which indicates that the task was canceled.
Events
ProgressChanged
public
event
Action<IUploadProgress>
ProgressChanged
Event called whenever the progress of the upload changes.
UploadSessionData
public
event
Action<IUploadSessionData>
UploadSessionData
Event called when an UploadUri is created. Not needed if the application program will not support resuming after a program restart.
Within the event, persist the UploadUri to storage. It is strongly recommended that the full path filename (or other media identifier) is also stored so that it can be compared to the current open filename (media) upon restart.