1

プロジェクトの画像を保存するために Amazon S3 を使用していますが、S3 のある場所から別の場所にいくつかの画像をコピーする必要があります。DB に保存されている古い/保存された画像パスがあり、新しいパスを使用してそれらを保存したいと考えています。

誰かが私を正しい方向に導いてくれませんか。調べているのですがCopyObjectRequest、どうすればいいのかわかりません。

どんな助けでも大歓迎です。

ありがとう

4

1 に答える 1

1

以下は、呼び出し元から関数に変数が渡されるoriginal一般的な例です。destination

public void DuplicateFileInCloud(string original, string destination)
{
    try
    {
        CopyObjectRequest request = new CopyObjectRequest();

        if (original.StartsWith("http"))
        {
            // example: http://jk-v30.s3.amazonaws.com/PredefinedFiles/Favicons/002.ico
            string bucket = getBucketNameFromUrl(original), // i.e. jk-v30
                    key = getKeyFromUrl(original);          // the path to your file: PredefinedFiles/Favicons/002.ico

            request.WithSourceBucket(bucket);
            request.WithSourceKey(key);
        }
        else
        {
            // same bucket: copy/paste operation
            request.WithSourceBucket(this.bucketName);
            request.WithSourceKey(original);
        }

        request.WithDestinationBucket(this.bucketName);
        request.WithDestinationKey(destination);
        request.CannedACL = S3CannedACL.PublicRead; // one way of setting public headers - see other below

        using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(this.accessKey, this.secretAccessKey))
        {
            S3Response response = client.CopyObject(request);
            response.Dispose();
        }
    }
    catch (AmazonS3Exception s3Exception)
    {
        throw s3Exception;
    }
}

これがあなたが探していたものであることを願っています!

設定public-read

response.Addheader("x-amz-acl","public-read");
于 2013-08-15T12:16:55.113 に答える