| 102 | return; |
| 103 | } |
| 104 | const copy = async () => { |
| 105 | try { |
| 106 | const sourceBucket = await prompter.input({ |
| 107 | message: "Enter source bucket name:", |
| 108 | }); |
| 109 | const sourceKey = await prompter.input({ |
| 110 | message: "Enter source key:", |
| 111 | }); |
| 112 | const destinationKey = await prompter.input({ |
| 113 | message: "Enter destination key:", |
| 114 | }); |
| 115 | |
| 116 | const command = new CopyObjectCommand({ |
| 117 | Bucket: destinationBucket, |
| 118 | CopySource: `${sourceBucket}/${sourceKey}`, |
| 119 | Key: destinationKey, |
| 120 | }); |
| 121 | await s3Client.send(command); |
| 122 | await copyFileFromBucket({ destinationBucket }); |
| 123 | } catch (err) { |
| 124 | console.error("Copy error."); |
| 125 | console.error(err); |
| 126 | const retryAnswer = await prompter.confirm({ message: "Try again?" }); |
| 127 | if (retryAnswer) { |
| 128 | await copy(); |
| 129 | } |
| 130 | } |
| 131 | }; |
| 132 | await copy(); |
| 133 | }; |
| 134 | // snippet-end:[javascript.v3.s3.scenarios.basic.CopyObject] |