I am attempting to upload an image to AWS s3 using Xamarin and experiencing this error:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
I've implemented as follows:
public TransferUtility s3transferUtility; public AmazonS3Client s3Client; public AWSObject() { } public void setupAWSCredentials(){ CognitoAWSCredentials credentials = new CognitoAWSCredentials( "eu-west-1:**", RegionEndpoint.EUWest1 ); var config = new AmazonS3Config() { RegionEndpoint = Amazon.RegionEndpoint.EUWest1, Timeout = TimeSpan.FromSeconds(30), UseHttp = true }; AWSConfigsS3.UseSignatureVersion4 = true; s3Client = new AmazonS3Client(credentials, config); this.s3transferUtility = new TransferUtility(s3Client); } public async Task UploadPhoto(string filename){ try { var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var filePath = Path.Combine(documentsPath, filename); TransferUtilityUploadRequest request = new TransferUtilityUploadRequest{BucketName = "xamarinbucket",FilePath = filePath,Key = "photoOne.png",ContentType = "image/png"}; CancellationToken cancellationToken = new CancellationToken(); await this.s3transferUtility.UploadAsync(request, cancellationToken); } catch (AmazonS3Exception s3Exception) { System.Console.WriteLine(s3Exception.StackTrace); } }
The functions are called as follows:
AWSObject awsObject = new AWSObject(); awsObject.setupAWSCredentials(); Task.Run(()=> awsObject.UploadPhoto("photoOne.png"));
Any suggestions ?
Answers
I am facing the same problem, please update if anybody got any solution
Any solution to this problem?
I'm also facing the problem any solution
Same problem here
same problem
I have fixed it, the problem was here
var s3Client = new AmazonS3Client(creds, RegionEndpoint.EUWest1);
I was using EUWest1 then I changed to RegionEndpoint.USEast1 and I got another error:
System.IO.IOException: Error writing request ---> System.Net.Sockets.SocketException: The socket has been shut down
Then I changed to RegionEndpoint.USEast2 and the error was fixed
I realize that my correct region was USEast2 in the url of my buckets that looks like this:
https://s3.console.aws.amazon.com/s3/home?region=us-east-2
At the end of the link you can see the region.
my code is this:
call first setupAsyncMethod then UploadFileAsync
I am using AWSSDK.S3 nuget plugin