2017-02-11 257 views
0

我试图在Unity内部的S3存储桶之间传输文件,并运行到我无法找到文档的神秘错误。两个桶都属于同一个帐户。在Unity中的Amazon S3存储桶之间传输文件

每当我创建资产时,我都会将它上传到Dev Bucket中的S3服务器,这很好用。当我准备好提交资产时,我想查看Prod Bucket中缺失的资产列表,并将其从Dev Bucket转移过来。从我的研究中,IAmazonS3. CopyObjectAsync()是应该完成这项任务的功能。 IAmazonS3.CopyObject()function而不是在亚马逊的Unity SDK中可用。

这里是我打电话试图复制对象的代码:

public void TestCopy() 
{ 
    var request = new CopyObjectRequest() 
    { 
     SourceBucket = mLoginData.DevBucket, 
     SourceKey = "myPic.jpg", 
     DestinationBucket = mLoginData.ProdBucket, 
     DestinationKey = "myPic.jpg" 
    }; 

    AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest; 

    Client.CopyObjectAsync(request,(responseObj) => 
    { 
     if (responseObj.Exception == null) 
     { 
      ResultText.text += "Copied Object"; 
     } 
     else 
     { 
      ResultText.text += "Got Exception: \n" + responseObj.Exception.ToString(); 
     } 
    }); 
} 

这导致未在Amazon Error Code documentation提到了“感动”错误代码:

Got Exception: 
Amazon.S3.AmazonS3Exception: Error making request with Error Code Moved and Http Status Code Moved. No further error information was returned by the service. Response Body: Encountered invalid redirect (missing Location header?) ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown. 
at Amazon.Runtime.Internal.UnityRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0 
at Amazon.Runtime.Internal.HttpHandler`1[System.String].GetResponseCallbackHelper (System.Object state) [0x00000] in <filename unknown>:0 
--- End of inner exception stack trace --- 
at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException (IExecutionContext executionContext, Amazon.Runtime.Internal.HttpErrorResponseException exception) [0x00000] in <filename unknown>:0 
at Amazon.Runtime.Internal.ExceptionHandler`1[T].Handle (IExecutionContext executionContext, System.Exception exception) [0x00000] in <filename unknown>:0 
at Amazon.Runtime.Internal.ErrorHandler.ProcessException (IExecutionContext executionContext, System.Exception exception) [0x00000] in <filename unknown>:0 
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsyncCallback (IAsyncExecutionContext executionContext) [0x00000] in <filename unknown>:0 

我知道我设置正确,因为我能够查看/列出存储区,上传/列出/删除文件到这两个存储区等。解决方案从Unity编辑器执行至关重要。

+0

这些新桶是? –

+0

不,这些桶已经有很多东西在过去4个月左右的时间里使用 –

回答

0

事实证明,CopyObjectAsync需要使用IAmazonS3客户端的实例,该实例配置了目标区域,而不是源区域。改变这个可以让复制品很好。

0

基于直接与S3 API合作的丰富经验,我有理由相信,这是你的错误:

PermanentRedirect

The bucket you are attempting to access must be addressed using the specified endpoint. Send all future requests to this endpoint.

301 Moved Permanently

我相信底层库是由你和Moved错误隐藏,这是该库的解释301错误。为什么它会这样做没有意义,但是再次,这就是为什么我更喜欢直接使用S3 REST API。

Encountered invalid redirect (missing Location header?) 

这与记录的行为一致。

To help you find these errors during development, this type of redirect does not contain a Location HTTP header that allows you to automatically follow the request to the correct location. Consult the resulting XML error document for help using the correct Amazon S3 endpoint.

http://docs.aws.amazon.com/AmazonS3/latest/dev/Redirects.html

如果有办法让你的手在这个XML响应体上,这可能会有帮助。

如果您使用全局(非特定区域)端点访问存储桶并且该存储桶位于除us-east-1以外的区域中,则此错误在存储桶创建的前几分钟内很常见,这就是为什么我问是否桶是新的。

如果存储桶不在us-east-1中,那么您可能需要在代码中某处传递一个区域,因为上面的错误表明您的请求到达了错误的区域端点。

+1

恰巧源桶在US-West-2和US-East-1的目标桶。我只是发现了这一点,而且似乎同意你的结论。我会尝试在复制功能中传递地区代码,并阅读如何在区域桶之间进行传输。感谢您的指导! –

相关问题