I have followed the DigitalOcean’s tutorial using aws and also I’ve followed one using multer and multerS3,but both tutorial throw me InvalidRequest: Malformed Request

This is what I have:

const multer = require('multer')
const multerS3 = require('multer-s3')
const aws = require('aws-sdk')

const { S3_ENDPOINT, BUCKET_NAME } = process.env;

const spacesEndpoint = new aws.Endpoint(S3_ENDPOINT)
const s3 = new aws.S3({
    endpoint: spacesEndpoint
})

const upload = multer({
    storage: multerS3({
        s3,
        bucket: BUCKET_NAME,
        acl: "public-read",
        metadata: (req,file,cb) =>{
            cb(null, {
                fieldname: file.fieldname
            })
        },
        key: (req, file, cb) =>{
            console.log(file)
            cb(null, file.originalname);
        }
    }),
}).single('upload');

module.exports={
    upload,
    s3
}

The server uses express, dotenv, cors, fs, the endpoint is instantiated like:
app.post(’/uploadFileRepo’, upload ,(req, res) => programCtrl.uploadFileRepo(req,res))

And uploadFileRepo only returns res.send(“Uploaded”)

And I sent the file through a Form

<form id        =  "repoForm"
                        enctype   =  "multipart/form-data"
                        action    =  "/uploadFileRepo"
                        method    =  "POST"
                    >
                        <div style="margin-top: 1em; margin-left: 1em;">
                            <input type="file" id="file" name="upload"/>  <br/>
                        </div>
                        <div style="text-align: right; margin-right: 2em;">
                            <button type="submit" class="btn btn-outline-primary">Upload</button>
                        </div>
                    </form>
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!