使用AWSSDK.S3C#

问题描述

我正在使我要管理的API所具有的一些手动任务自动化,并且在尝试自动上载图像时遇到了问题。我遇到的错误如下:

Error making request with Error Code SignatureDoesNotMatch and Http Status Code Forbidden. No further error @R_376_4045@ion was returned by the service.    
at Amazon.Runtime.HttpWebRequestMessage.<GetResponseAsync>d__20.MoveNext()
   at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Amazon.Runtime.Internal.HttpHandler`1.<InvokeAsync>d__9`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at Amazon.Runtime.Internal.RedirectHandler.<InvokeAsync>d__1`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Amazon.S3.Internal.AmazonS3ResponseHandler.<InvokeAsync>d__1`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()

我尝试过TransferUtilityUploadRequestPutObjectRequest,每次都遇到相同的错误

图片上传功能

public static async Task<bool> UploadImage(string name,string filePath,string bucketPath)
{
    IAmazonS3 s3Client = new AmazonS3Client(Consts.S3AccessKey,Consts.S3SecretKey,new AmazonS3Config { ServiceURL = "https://sfo2.digitaloceanspaces.com" });

    try
    {
        //var fileTransferUtility = new TransferUtility(s3Client);
        //var fileTransferUtilityRequest = new TransferUtilityUploadRequest
        //{
        //    BucketName = Consts.S3BucketName + @"/" + bucketPath,//    FilePath = filePath,//    Key = name,//    CannedACL = S3CannedACL.PublicRead
        //};
        //fileTransferUtility.Upload(fileTransferUtilityRequest);

        var image = new PutObjectRequest
        {
            BucketName = Consts.S3BucketName + @"/" + bucketPath,FilePath = filePath,Key = name,CannedACL = S3CannedACL.PublicRead,ContentType = "image/png"
        };

        await s3Client.PutObjectAsync(image);
        return true;
    }
    catch (AmazonS3Exception e)
    {
        Console.WriteLine("Error encountered ***. Message:'{0}' when writing an object",e.Message);
    }
    catch (Exception e)
    {
        Console.WriteLine("UnkNown encountered on server. Message:'{0}' when writing an object",e.Message);
        if (e.Message.Contains("disposed"))
            return true;
    }

    return false;

}

我的KeybucketPath 中有空格,但是我尝试不使用空格,但仍然遇到错误

有想法吗?

编辑

看起来与https://github.com/aws/aws-sdk-net/issues/965有关 我的钥匙里有(和)。一旦我删除了它们,它就会起作用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)