Question
Upload success with DO space but never show
I’m using DO space for the first time to upload images and documents. I used multer and multer-s3 to upload multiple images. The function works fine and show successful without error. But DO space doesn’t show any updates. The files doesn’t upload to the DO space. I tried URL but no such key.
I set my DO Space:
- Enable File Listing
- Enable CDN
- CORS: allow all the wildcard domain
const bucket = 'MY_DO_UNIQUE_NAME';
const spacesEndpoint = new AWS.Endpoint('sgp1.digitaloceanspaces.com');
const s3 = new AWS.S3({
endpoint: spacesEndpoint,
accessKeyId: process.env.DO_ACCESS_KEY,
secretAccessKey: process.env.DO_SECRET_KEY
});
const upload = multer({
storage: multerS3({
s3:s3,
bucket: bucket,
acl: 'public-read',
key: function (request, file, cb) {
console.log(file);
cb(null, file.originalname);
}
}),
}).array('file', 100);
upload(req, res, function (error, file, data) {
if (error) {
console.log(error);
return response.redirect("/error");
}
console.log('File uploaded successfully.');
});
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.
×