无法在PCL项目中使用AWS

本文关键字:AWS 项目 PCL | 更新日期: 2023-09-27 18:22:14

在我的PCL项目中,我添加了以下两个NuGet包:

  • AWSSDK.Core
  • AWSSDK.S3

像这样使用

private AmazonS3Client _client;
private TransferUtility _trans;
public MyClass()
{
    AmazonS3Config config = new AmazonS3Config ();
    config.ServiceURL = "s3-eu-west-1.amazonaws.com";
    config.UseHttp = true;
    config.RegionEndpoint = RegionEndpoint.EUWest1;
    _client = new AmazonS3Client (_access, _secret, config);
    _trans = new TransferUtility (_client);
}
public async void UploadFile(string path, string key)
{
    TransferUtilityUploadRequest up = new TransferUtilityUploadRequest();
    up.BucketName = "mybucket";
    up.FilePath = path;
    up.Key = key;
    up.UploadProgressEvent += up_UploadProgressEvent;
    await _trans.UploadAsync(up);
}

现在,当我尝试使用NUnit测试这种方法时,我得到了以下错误

此功能未在的可移植版本中实现装配您应该参考您的主要应用程序项目,以便参考特定平台实施

StackTrace是

at PCLStorage.FileSystem.get_Current()
   at Amazon.S3.Transfer.TransferUtility.validate(TransferUtilityUploadRequest request) in d:'Jenkins'jobs'v3-stage-release'workspace'AWSDotNetPublic'sdk'src'Services'S3'Custom'Transfer'TransferUtility.cs:line 367
   at Amazon.S3.Transfer.TransferUtility.GetUploadCommand(TransferUtilityUploadRequest request, SemaphoreSlim asyncThrottler) in d:'Jenkins'jobs'v3-stage-release'workspace'AWSDotNetPublic'sdk'src'Services'S3'Custom'Transfer'_async'TransferUtility.async.cs:line 281
   at Amazon.S3.Transfer.TransferUtility.UploadAsync(TransferUtilityUploadRequest request, CancellationToken cancellationToken) in d:'Jenkins'jobs'v3-stage-release'workspace'AWSDotNetPublic'sdk'src'Services'S3'Custom'Transfer'_async'TransferUtility.async.cs:line 184

无法在PCL项目中使用AWS

您应该在特定于平台的项目中添加Core和S3包。

如果你正在使用Xamarin,你必须在PCL中添加软件包,也可以在你的android或iOS项目中添加。