When I upload to spaces with s3client, why do I get projectName.bucketName at the root of my path?

I’m getting started with Spaces. I’m successfully uploading images from a node backend with s3client and a PutObjectCommand. PutObjectCommand requires a Bucket argument, and it works when I put projectName.bucketName. To my surprise (and distaste), this argument is prepended to the Key, and so finds itself in the URL of the uploaded image. Why is this, and can I turn it off?

This is my upload command…

    const command = new PutObjectCommand({
        Bucket: "simplyfirst.simplyfirst",
        Body: arr,
        ACL: "public-read",
        ContentType: contentType
    try {
        const response = await s3Client.send(command);
        return NextResponse.json({newFilename:filename})
    } catch (err) {
        return new NextResponse("Error", { status: 500 })

…which gives me this in Spaces…

image alt text
image caption

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
May 6, 2024

Hi there,

Is your Bucket name actually simplyfirst.simplyfirst? If so, I believe that the dot in the name might be causing an issue here.

Usually having a dot in your Bucket name is not very recommended as it can break the FQDN of the spaces endpoint.

I could suggest trying with a bucket name which does not contain a dot.

If this is not the case, the Bucket name should not be included in the Key parameter. Instead, use only the path inside the bucket. This way, your uploaded objects will not include projectName.bucketName in their paths. I could suggest adding some console log statements to see if this is actually the case.

If none of those help, feel free to share your client definition as well and I will be happy to try and set this up on my end to further test it.



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel