Try
dim accessKeyId As String = Config.AccessKeyId
dim accessKeySecret As String = Config.AccessKeySecret
dim endpoint As String = Config.Endpoint
dim client As OssClient = New OssClient(endpoint, accessKeyId, accessKeySecret)
dim key As String = "GetObjectSample"
dim fileToUpload As String = Config.FileToUpload
dim dirToDownload As String = Config.DirToDownload
dim _event As AutoResetEvent = New AutoResetEvent(False)
client.PutObject(bucketName, key, fileToUpload)
Dim result = client.GetObject(bucketName, key)
Using requestStream = result.Content
Using fs = File.Open(dirToDownload & "/sample.data", FileMode.OpenOrCreate)
Dim length As Integer = 4 * 1024
Dim buf = New Byte(length - 1) {}
Do
length = requestStream.Read(buf, 0, length)
fs.Write(buf, 0, length)
Loop While length <> 0
End Using
End Using
Console.WriteLine("Get object succeeded")
Catch ex As OssException
Console.WriteLine("Failed with error code: {0}; Error info: {1}. " & vbLf & "RequestID:{2}" & vbTab & "HostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId)
Catch ex As Exception
Console.WriteLine("Failed with error info: {0}", ex.Message)
End Try