How to rename files and folder in Amazon S3?

后端 未结 19 2328
暖寄归人
暖寄归人 2020-11-28 03:01

Is there any function to rename files and folders in Amazon S3? Any related suggestions are also welcome.

19条回答
  •  清酒与你
    2020-11-28 03:32

    I've just got this working. You can use the AWS SDK for PHP like this:

    use Aws\S3\S3Client;
    
    $sourceBucket = '*** Your Source Bucket Name ***';
    $sourceKeyname = '*** Your Source Object Key ***';
    $targetBucket = '*** Your Target Bucket Name ***';
    $targetKeyname = '*** Your Target Key Name ***';        
    
    // Instantiate the client.
    $s3 = S3Client::factory();
    
    // Copy an object.
    $s3->copyObject(array(
        'Bucket'     => $targetBucket,
        'Key'        => $targetKeyname,
        'CopySource' => "{$sourceBucket}/{$sourceKeyname}",
    ));
    

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

提交回复
热议问题