我正在尝试使用适用于.Net的AWS Sdk将文件上传到S3bucket。
我正在上传如下文件:
Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button2.Click
Await AddFileToFolderAsync(file, bucketName, fld)
' here file is file's fullpath,buckatename is
' available s3bucket name,
' fld is target folder path into that s3bucket.
End Sub
Public Async Function AddFileToFolderAsync(FileName As String, bucketName As String, folderName() As String) As Task
Try
If Not AmazonS3Util.DoesS3BucketExistV2(S3client, bucketName) Then
MessageBox.Show("Bucket does not exist")
Dim fname() As String = folderName
CreateFolder(bucketName, fname)
Else
Dim keyname As String = "" 'destination path(s3 bucket folder)
Dim filepath As String = FileName 'current file's local fullpath
Dim fname As String = Path.GetFileName(FileName) 'filename
For i = 0 To folderName.Length - 1
keyname += folderName(i) & "/"
Next
keyname += fname 'bucket's target folder /fname (eg:folder/subfolder/file.mp4)
Dim fileTransferUtility = New TransferUtility(S3client)
Dim fileTransferUtilityRequest = New TransferUtilityUploadRequest With {
.BucketName = bucketName,
.FilePath = filepath,
.StorageClass = S3StorageClass.Standard,
.ServerSideEncryptionMethod = ServerSideEncryptionMethod.None,
.PartSize = 6291456,
.Key = keyname,
.ContentType = "*.*"}
AddHandler fileTransferUtilityRequest.UploadProgressEvent, New EventHandler(Of UploadProgressArgs)(AddressOf UploadRequest_UploadPartProgressEvent)
Await fileTransferUtility.UploadAsync(fileTransferUtilityRequest)
End If
Catch ex As AmazonS3Exception
MessageBox.Show(ex.Message + " Upload task canceled.")
Catch ex As Exception
MessageBox.Show(ex.Message + " Upload task canceled.")
End Try
End Function
上面的代码中有事件处理程序:
AddHandler fileTransferUtilityRequest.UploadProgressEvent, New EventHandler(Of UploadProgressArgs)(AddressOf UploadRequest_UploadPartProgressEvent)
它确实:
Public Function UploadRequest_UploadPartProgressEvent(ByVal sender As Object, ByVal e As UploadProgressArgs)
' here uploadprogressargs class has two variable which are having
' totalbytes and transferedbytes(those are e.transferedbytes and e.totalbytes)
End Function
现在,我的问题是:如何基于ProgrssValue
增加e.TransferredBytes
?
希望大家都能理解我的问题。我是.Net的初学者。