No RegionEndpoint or ServiceURL configured

后端 未结 5 2004
野性不改
野性不改 2021-01-01 09:35

I am writing code to upload files to AWS S3 and receiving this exception:

AmazonClientException: No RegionEndpoint or ServiceURL configured

5条回答
  •  滥情空心
    2021-01-01 10:18

    My access key id and secret key are can be used.
    Therefore I give up using TransferUtility Class and chosing another Class named PutObjectRequest to upload my files
    attontion: PutObjectRequest’s Property Key,it's directory name and file name must equal to local files' directory name and file name.
    codes here:

            String s3Path = "987977/Baby.db";
            Console.WriteLine("Ready to upload");
            AWSCredentials credentials;
            credentials = new BasicAWSCredentials(accessKeyID.Trim(), secretKey.Trim());
            AmazonS3Client s3Client = new AmazonS3Client(accessKeyID.Trim(), secretKey.Trim(), Amazon.RegionEndpoint.USEast1);
            Console.WriteLine("Successful verification");
            Console.WriteLine("Check: if the bucket exists");
            if (!CheckBucketExists(s3Client, bucketName))
            {
                s3Client.PutBucket(bucketName);
                Console.WriteLine("Creat bucket");
            }
            string localPath = @"E:\telerikFile\987977\Baby.db";
            PutObjectRequest obj = new PutObjectRequest();
            var fileStream = new FileStream(localPath, FileMode.Open, FileAccess.Read);
      //      obj.FilePath= @"E:\telerikFile\987977\Baby.db";
            obj.InputStream = fileStream;
            obj.BucketName = bucketName;
            obj.Key = s3Path;
           // obj.ContentBody = "This is sample content...";
            obj.CannedACL = S3CannedACL.PublicRead;
            Console.WriteLine("uploading");
            // default to set public right  
            s3Client.PutObject(obj);
    

提交回复
热议问题