从Visual Studio将文件上传到Amazon AWS云时出错

时间:2019-12-30 11:23:34

标签: .net amazon-s3

我正在尝试从Visual Studio 2015将文件上传到AWS Cloud。但是我收到错误消息引发了状态为NameResolutionFailure的WebException。

我已经尝试过通过智能感知来使用所有区域,但这没有用。

下面是我的代码。任何人都可以帮忙。

public void sendMyFileToS3(System.IO.Stream localFilePath, string bucketName, string subDirectoryInBucket, string fileNameInS3)
{
    IAmazonS3 client = new AmazonS3Client(RegionEndpoint.USWest2);            
    TransferUtility utility = new TransferUtility(client);
    TransferUtilityUploadRequest request = new TransferUtilityUploadRequest()
     if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
            {
                request.BucketName = bucketName;
            }
            else
            {    
                request.BucketName = bucketName + @"/" + subDirectoryInBucket;
            }
            request.Key = fileNameInS3; //file name up in S3  
            request.InputStream = localFilePath;
            try
            {
                utility.Upload(request);
            }
            catch (Exception ex)
            {
                throw ex;
            }
}

1 个答案:

答案 0 :(得分:0)

我在上面的代码中唯一想到的是您的代码不在USWest2下,您可以确认吗?