![](/img/trans.png)
[英]How to copy/move object from one bucket to another in AWS S3 in .Net Core
[英]AWS S3 How to move files from a bucket to another bucket in a different region
我在不同地區有兩個存儲桶,B1位於APSoutheast2(悉尼),另一個(B2)位於USWest1(美國西部(加利福尼亞北部))。 我正在嘗試使用AWS S3 SDK(.NET)將某些文件從B1移到B2,但似乎看不到一種簡單的方法。
這是我的示例代碼:
var sydneyClient = new AmazonS3Client("accessKeyID", "secretKey",
RegionEndpoint.APSoutheast2)
var fileInfo = new S3FileInfo(sydneyClient, "b1", "filePath");
if (!fi.Exists)
{
return;
}
fileInfo.MoveTo("b2", "filePath");
這給了我以下錯誤:
Amazon.S3.AmazonS3Exception: 'Error making request with Error Code
MovedPermanently and Http Status Code MovedPermanently. No further error
information was returned by the service.'
我認為這是因為b2與執行此操作時位於不同的區域中:
var listAllRequest = new ListObjectsRequest();
listAllRequest.BucketName = "b2";
var listAllResponse = sydneyClient.ListObjects(listAllRequest);
我懂了:
The bucket you are attempting to access must be addressed using the specified
endpoint. Please send all future requests to this endpoint
我知道我的“ sydneyClient”無法訪問在美國創建的另一個存儲桶是有道理的,因為我在創建該存儲桶時將其指定為“ RegionEndpoint.APSoutheast2”,並且根據AWS文檔每個區域都是獨立的。
如果我嘗試將文件從b1移到APSoutheast2中的另一個存儲桶,則可以正常工作。
我知道我可以將文件從b1下載到本地存儲,為b2創建另一個AmazonS3Client,然后執行上傳。 但是在這種情況下,是否有一種簡單的方法將文件從b1移到另一個區域中的存儲桶?
謝謝
Amazon S3沒有“移動”命令。 相反,您應該使用AmazonS3Client.CopyObject方法 ,並指定:
public virtual CopyObjectResponse CopyObject(
String sourceBucket,
String sourceKey,
String destinationBucket,
String destinationKey
)
然后,刪除原始對象。
這適用於存儲桶之間以及區域之間。 將請求發送到目標區域 (即,目標桶所在的區域)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.