I’ve been tackling this for the last 8 hours to no avail. Everything seems to be uploading to my DigitalOcean Spaces bucket just fine. However, when I copy the CDN url, I just get the “corrupted image” square (see below). The file sizes within DigitalOcean shows the correct size of the uploaded image. I’m using express, express-fileupload, and aws-sdk/client-s3.
Here is my config:
const config = {
endpoint: "https://sfo3.digitaloceanspaces.com",
region: "us-west-1",
credentials: {
accessKeyId: process.env.DIGITAL_OCEAN_ACCESS_KEY,
secretAccessKey: process.env.DIGITAL_OCEAN_SECRET_KEY,
},
};
const client = new S3Client(config);
Here is my upload code – I receive the file from my front end:
module.exports.testFileUpload = async (req, res, next) => {
console.log(req.files.profilePicture.data); // Returns the buffer
console.log(typeof req.files.profilePicture.data); // Returns object
const input = {
Body: req.files.profilePicture.data,
Bucket: "my-bucket-name",
Key: `userProfiles/${req.files.profilePicture.name}`,
ACL: "public-read",
ContentType: req.files.profilePicture.mimetype,
};
try {
const command = new PutObjectCommand(input);
const response = await client.send(command);
console.log("response", response); // I receive a response with a 200 status code
} catch (err) {
console.log(err); // I'm not getting an error
}
};
This is what I get when I enter the CDN url into my browser
I originally started this project with Cloudinary and it worked just fine. I want to switch to DigitalOcean because of the large storage space at a low cost. If anyone has any ideas, it would be greatly appreciated :’)
I feel like I’ve included all of the necessary bits of information, but please let me know if you feel I’m missing any key parts to help figure out what’s going on.