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 请求,System.Byte[] 缓冲区,Int32 偏移量,Int32 大小,System.AsyncCallback cb,System.Object 状态)[0x0001f] 在 /Developer/MonoTouch/Source/ mono/mcs/class/System/System.Net/WebConnection.cs:1033 在 System.Net.WebConnectionStream.BeginWrite (System.Byte [] 缓冲区,Int32 偏移量,Int32 大小,System.AsyncCallback cb,System.Object 状态)[ 0x0026c] 在 /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnectionStream.cs:541

github repo 已经一年没有更新了,所以它可能只是坏了?我要做的就是 PUT 和 DELETE 文件,所以我的下一步是使用 RestSharp 访问 REST API,而不是使用包装器,但肯定这是其他人已经做过的事情,任何人都可以解释一下吗?

4

1 回答 1

0

签出:使用 xamarin c# 上传亚马逊 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 canellationToken = new System.Threading.CancellationToken();
await transferUtility.UploadAsync(request, canellationToken);
于 2017-03-29T05:38:22.970 回答