VS2015, .Net 4.0
Used NuGet to get the latest AWSSDK.S3 v3.3.5.3 and AWSSDK.Core v3.3.8 references.

I'm trying to use the AWS SDK to upload a file from our server to an Amazon S3 account which works just fine for files 2gb or smaller but one client we generate a file that when it's gzipped ends up being around 3.71gb and our upload routine errors out because File.ReadAllBytes() only handles up to 2gb.

I've tried creating the FileStream manually and using .CopyTo() to copy it into the MemoryStream before passing it into the AWK SDK PutObjectRequest, but I'm still getting this exception:
Code:
System.IO.IOException: Stream was too long.
   at AmazonS3Utilities.UploadFile.UploadFile(String FilePath, String BucketPath, String UsrName, String Pass, RegionEndpoint EndPt) in C:\TFS\DataTeam Projects\Utilities\AmazonS3Utilities\AmazonS3Utilities\UploadFile.vb:line 123
   at AmazonS3Utilities.UploadFile.UploadFile(String FilePath, String BucketPath) in C:\TFS\DataTeam Projects\Utilities\AmazonS3Utilities\AmazonS3Utilities\UploadFile.vb:line 90
   at UploadFileS3.Main.Main(String[] Args) in C:\TFS\DataTeam Projects\Utilities\AmazonS3Utilities\UploadFileS3\Main.vb:line 48
Here's my vb.net code:
vb.net Code:
  1. Public Function UploadFile(FilePath As String, BucketPath As String, UsrName As String, Pass As String, EndPt As RegionEndpoint) As Boolean
  2.         Dim Output As Boolean = False
  3.  
  4.         UsrName = UsrName.Trim()
  5.         Pass = Pass.Trim()
  6.         BucketPath = BucketPath.Trim()
  7.         FilePath = FilePath.Trim()
  8.  
  9.         If UsrName.Length > 0I Then
  10.             If Pass.Length > 0I Then
  11.                 If File.Exists(FilePath) Then
  12.                     Dim s3Client As AmazonS3Client = Nothing
  13.                     Dim memStream As MemoryStream = Nothing
  14.                     Dim fileStream As FileStream = Nothing
  15.                     Try
  16.                         s3Client = New AmazonS3Client(UsrName, Pass, EndPt)
  17.                         'memStream = New MemoryStream(File.ReadAllBytes(FilePath))
  18.                         memStream = New MemoryStream
  19.                         fileStream = New FileStream(FilePath, FileMode.Open, FileAccess.Read)
  20.                         fileStream.CopyTo(memStream)
  21.  
  22.                         Dim rr As New PutObjectRequest() With {.BucketName = BucketPath, .Key = Path.GetFileName(FilePath), .InputStream = memStream}
  23.                         Dim response As PutObjectResponse = s3Client.PutObject(rr)
  24.  
  25.                         Output = response.HttpStatusCode = HttpStatusCode.OK
  26.                     Catch ex As Exception
  27.                         Throw ex
  28.                     Finally
  29.                         If fileStream IsNot Nothing Then
  30.                             fileStream.Close()
  31.                             fileStream.Dispose()
  32.                         End If
  33.  
  34.                         If memStream IsNot Nothing Then
  35.                             memStream.Close()
  36.                             memStream.Dispose()
  37.                         End If
  38.  
  39.                         If s3Client IsNot Nothing Then
  40.                             s3Client.Dispose()
  41.                         End If
  42.                     End Try
  43.                 Else
  44.                     Throw New FileNotFoundException($"File {Path.GetFileName(FilePath)} was not found")
  45.                 End If
  46.             Else
  47.                 Throw New ArgumentNullException("Password cannot be blank or all spaces")
  48.             End If
  49.         Else
  50.             Throw New ArgumentNullException("UserName cannot be blank or all spaces")
  51.         End If
  52.  
  53.         Return Output
  54.     End Function
I do see that .Net offers a BufferedStream, could I somehow use the FileStream.CopyTo() into a BufferedStream that will then .CopyTo() the MemoryStream?