By skeddtemp
I want to copy file.
This works perfectly fine, and spits out a list of all files in my space:
s3.listObjects({Bucket: "lospec"}, function(err, data) {});
This code on the other hand:
s3.copyObject({
Bucket: "lospec",
Key: newAvatarPath,
CopySource: oldAvatarPath,
}, function(err, data) {});
Returns this error, claiming the bucket name is wrong:
{ InvalidBucketName: null
0|lospec | at Request.extractError (/home/lospec/htdocs/node_modules/aws-sdk/lib/services/s3.js:714:35)
0|lospec | at Request.callListeners (/home/lospec/htdocs/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
0|lospec | at Request.emit (/home/lospec/htdocs/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
0|lospec | at Request.emit (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:688:14)
0|lospec | at Request.transition (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:22:10)
0|lospec | at AcceptorStateMachine.runTo (/home/lospec/htdocs/node_modules/aws-sdk/lib/state_machine.js:14:12)
0|lospec | at /home/lospec/htdocs/node_modules/aws-sdk/lib/state_machine.js:26:10
0|lospec | at Request.<anonymous> (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:38:9)
0|lospec | at Request.<anonymous> (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:690:12)
0|lospec | at Request.callListeners (/home/lospec/htdocs/node_modules/aws-sdk/lib/sequential_executor.js:116:18)
0|lospec | at Request.emit (/home/lospec/htdocs/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
0|lospec | at Request.emit (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:688:14)
0|lospec | at Request.transition (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:22:10)
0|lospec | at AcceptorStateMachine.runTo (/home/lospec/htdocs/node_modules/aws-sdk/lib/state_machine.js:14:12)
0|lospec | at /home/lospec/htdocs/node_modules/aws-sdk/lib/state_machine.js:26:10
0|lospec | at Request.<anonymous> (/home/lospec/htdocs/node_modules/aws-sdk/lib/request.js:38:9)
0|lospec | message: null,
0|lospec | code: 'InvalidBucketName',
0|lospec | region: null,
0|lospec | time: 2021-09-13T21:33:59.741Z,
0|lospec | requestId: 'tx00000000000001e4c7898-00613fc3c7-18019e73-nyc3c',
0|lospec | extendedRequestId: undefined,
0|lospec | cfId: undefined,
0|lospec | statusCode: 400,
0|lospec | retryable: false,
0|lospec | retryDelay: 39.853977480976695 }
What am I doing wrong? How is my bucket name wrong?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello @skeddtemp
you can try this
var params = {
Bucket: 'dotest2',
CopySource: "/lospec/oldAvatarPath",
Key: "NewAvatarPath"
};
s3.copyObject(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
from your snippet, I see that you are not declaring the bucket name in the CopySource. The CopySource has the following format:
CopySource: "/BUCKET-NAME/Object-name",
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.