Question

Spaces copyObject with aws-sdk: InvalidBucketName Error

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?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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",