Report this

What is the reason for this report?

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

Posted on May 2, 2024

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",
        Key,
        Body: arr,
        ACL: "public-read",
        ContentType: contentType
    });
    try {
        const response = await s3Client.send(command);
        console.log(response);
        return NextResponse.json({newFilename:filename})
    } catch (err) {
        console.error(err);
        return new NextResponse("Error", { status: 500 })
    }

…which gives me this in Spaces…

image alt text
image caption


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!

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.

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.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.