DriveClientUploadFileAsync(FileInfo, File, ActionIUploadProgress, CancellationToken, String) Method
Asynchronously uploads a file in the specified folder.
Namespace: DevCase.ThirdParty.Google.DriveAssembly: DevCase.net48.ThirdParty.GoogleServices (in DevCase.net48.ThirdParty.GoogleServices.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
public Task<KeyValuePair<ResumableUpload, File>> UploadFileAsync(
FileInfo srcFile,
File dstFile,
Action<IUploadProgress> progressHandler,
CancellationToken cancellationToken,
params string[] parentFolderIds
)
Public Function UploadFileAsync (
srcFile As FileInfo,
dstFile As File,
progressHandler As Action(Of IUploadProgress),
cancellationToken As CancellationToken,
ParamArray parentFolderIds As String()
) As Task(Of KeyValuePair(Of ResumableUpload, File))
Dim instance As DriveClient
Dim srcFile As FileInfo
Dim dstFile As File
Dim progressHandler As Action(Of IUploadProgress)
Dim cancellationToken As CancellationToken
Dim parentFolderIds As String()
Dim returnValue As Task(Of KeyValuePair(Of ResumableUpload, File))
returnValue = instance.UploadFileAsync(srcFile,
dstFile, progressHandler, cancellationToken,
parentFolderIds)
public:
Task<KeyValuePair<ResumableUpload^, File^>>^ UploadFileAsync(
FileInfo^ srcFile,
File^ dstFile,
Action<IUploadProgress^>^ progressHandler,
CancellationToken cancellationToken,
... array<String^>^ parentFolderIds
)
member UploadFileAsync :
srcFile : FileInfo *
dstFile : File *
progressHandler : Action<IUploadProgress> *
cancellationToken : CancellationToken *
parentFolderIds : string[] -> Task<KeyValuePair<ResumableUpload, File>>
No code example is currently available or this language may not be supported.
- srcFile FileInfo
-
The source file to upload.
- dstFile File
-
The metadata of the file being uploaded.
In the metadata you can specify values like the destination filename, description, folder destination, etc...
- progressHandler ActionIUploadProgress
-
A event handler that will receive progress changes of the upload operation.
- cancellationToken CancellationToken
-
A cancellation token to cancel the upload operation.
- parentFolderIds String
-
The identifier of the parent folder(s) where to upload the file.
This paramenter can be empty (nul).
TaskKeyValuePairResumableUpload,
File
The resulting
TaskTResult.
This is a code example.
No code example is currently available or this language may not be supported.
Private Async Sub UploadFile()
Dim client As New DriveClient("C:\GoogleSecrets.json", "yourmail@gmail.com", DriveScopes.Full)
Dim credential As UserCredential = Await client.AuthorizeAsync()
Dim srcFile As New FileInfo("C:\File.ext")
Dim dstFolder As Google.Apis.Drive.v3.Data.File = client.GetFoldersByName("Folder Name").Single()
Dim dstFile As New Global.Google.Apis.Drive.v3.Data.File
With dstFile
.Name = "New File Name"
.Description = "File Description"
.Parents = {dstFolder.Id}
End With
Dim result As KeyValuePair(Of Google.Apis.Upload.ResumableUpload, Google.Apis.Drive.v3.Data.File) =
Await client.UploadFileAsync(srcFile, dstFile, AddressOf Me.Upload_ProgressChanged, Nothing)
Dim sb As New Global.System.Text.StringBuilder()
With sb
.AppendLine(String.Format("Id: {0}", result.Value.Id))
.AppendLine(String.Format("Name: {0}", result.Value.Name))
.AppendLine(String.Format("Size: {0}", result.Value.Size))
.AppendLine(String.Format("MIME type: {0}", result.Value.MimeType))
.AppendLine(String.Format("Date Created: {0}", result.Value.CreatedTime?.ToString()))
.AppendLine(String.Format("Url: {0}", If(result.Value.WebContentLink, result.Value.WebViewLink)))
.AppendLine(String.Format("Parent Folder Ids: {0}", String.Join(",", If(result.Value.Parents, {"nul"}))))
End With
Console.WriteLine(sb.ToString())
End Sub
Public Sub Upload_ProgressChanged(ByVal e As Google.Apis.Upload.IUploadProgress)
Select Case e.Status
Case Google.Apis.Upload.UploadStatus.Starting
Console.WriteLine("Starting upload...")
Case Google.Apis.Upload.UploadStatus.Uploading
Console.WriteLine("Bytes sent: {0}", e.BytesSent)
Case Google.Apis.Upload.UploadStatus.Completed
Console.WriteLine("Upload completed.")
Case Google.Apis.Upload.UploadStatus.Failed
Console.WriteLine("Upload failed. Reason: {0}", e.Exception.Message)
Case Else
' Do Nothing.
End Select
End Sub
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.