Xamarin Amazon S3上传

3
有人在Xamarin上使用Amazon S3文件上传有经验吗?这应该很简单,但我无法让它正常工作。我正在尝试使用https://github.com/xamarin/amazon来上传文件,就像这样:
try 
{
    var client = new AmazonS3Client ("REDACTED", "REDACTED");
    var transferUtility = new TransferUtility (client);
    TransferUtilityUploadRequest request = new TransferUtilityUploadRequest()
        .WithBucketName("bucketname")
        .WithFilePath(image.LocalPath)
        .WithKey("rodsTest")
        .WithTimeout(5 * 60 * 1000);
    transferUtility.Upload(request);

} catch (Exception ex){
    Console.WriteLine (ex.ToString ());
}

但是我收到了这个异常:

System.ObjectDisposedException:对象在被处理后已被释放。在 System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x0001f] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnection.cs:1033 at System.Net.WebConnectionStream.BeginWrite (System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x0026c] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnectionStream.cs:541

该 GitHub 存储库已经一年没有更新了,所以也许它只是出现了故障?我想要做的就是 PUT 和 DELETE 文件,因此我的下一步是使用 RestSharp 命中 REST API,而不是使用一个包装器,但肯定有其他人已经这样做过,有人能够给予一些启示吗?

1个回答

0

请查看:使用Xamarin C#上传到Amazon S3文件

AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = serviceUrl; // amazon s3 URL                              
config.UseHttp = true;
config.RegionEndpoint =Amazon.RegionEndpoint.APNortheast1; // your region

AmazonS3Client client = new AmazonS3Client(accessKey,
    secretAccessKey, config);

TransferUtility transferUtility = new TransferUtility(client);

TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.BucketName = s3Bucket;
request.FilePath = filePath; // local file path 

// Test that the path is correct
UIImage image = UIImage.FromFile(filePath);

System.Threading.CancellationToken cancellationToken = new System.Threading.CancellationToken();
await transferUtility.UploadAsync(request, cancellationToken);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接