Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ const MAO = require('multer-aliyun-oss');
✗ import MAO from 'multer-aliyun-oss'; // ESM not supported
Package is CommonJS only, no ESM export. Use require().
default
✓ const upload = multer({ storage: MAO({...}) });
✗ const upload = multer({ storage: new MAO({...}) }); // MAO is not a constructor
MAO is a function that returns a storage engine object, not a class.
destination
✓ destination: (req, file, cb) => cb(null, 'uploads/')
✗ destination: '/uploads' // will be ignored; must use function or empty string
If set as string, it's used directly; but to mimic multer DiskStorage, use function.
Express server with single file upload to AliYun OSS using multer middleware.
const express = require('express');
const multer = require('multer');
const MAO = require('multer-aliyun-oss');
const app = express();
const upload = multer({
storage: MAO({
config: {
region: process.env.OSS_REGION ?? '',
accessKeyId: process.env.OSS_ACCESS_KEY_ID ?? '',
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET ?? '',
bucket: process.env.OSS_BUCKET ?? '',
},
destination: 'uploads',
filename: (req, file, cb) => {
cb(null, Date.now() + '-' + file.originalname);
}
})
});
app.post('/upload', upload.single('file'), (req, res) => {
console.log(req.file);
res.send('OK');
});
app.listen(3000);
Errors
Common errors & fixes
TypeError: Cannot read property 'region' of undefined
config object is missing or misspelled properties.
fixEnsure 'config' object contains region, accessKeyId, accessKeySecret, and bucket strings.
TypeError: MAO is not a constructor
Attempting to use 'new MAO()' instead of calling as a function.
fixUse 'multers()' (no new).
Error: ENOENT: no such file or directory, open '...'
Incorrect destination path; this package tries to create a local temp file before uploading? Actually it streams directly, but this error may appear if the OS cannot handle streaming.
fixCheck destination path and ensure writable permissions. Use absolute path or empty destination to use root.
Audit
Dependencies
@ali-ossrequiredRequired for interacting with AliYun OSS API
multerrequiredPeer dependency; the storage engine is used with multer