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…
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 theKey
parameter. Instead, use only the path inside the bucket. This way, your uploaded objects will not includeprojectName.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