multer-oss
multer upload files to aliyun oss directly.
⭐️ Features
- support upload files to oss
- support reduce jpeg, jpg and png size automatically
- support es7 features async and await
- support compressed by gzip by default
🎉 Install
npm install multer-oss-new
🚀 Usage
init oss storage
const OSSStorage = const zlib = const storage = oss: // required region: 'oss-region' internal: false accessKeyId: 'access-key-id' accessKeySecret: 'access-key-secret' bucket: 'bucket' destination: async { return '' // return destination folder path, optional, '' is default value } filename: async { return fileoriginalname // return file name, optional, file.originalname is default value } stream: async { return filestream // compress strem in gzip } options: async { // read more https://www.npmjs.com/package/ali-oss#putstreamname-stream-options return contentLength: filesize headers: 'Content-Encoding': gzip 'Content-Disposition': fileoriginalname 'Expires': 3600000 // in ms }
if you already have an oss client, you can pass it to opt directly
const OSS = const OSSStorage = const zlib = const ossClient = region: 'oss-region' internal: false accessKeyId: 'access-key-id' accessKeySecret: 'access-key-secret' bucket: 'bucket'const storage = client: ossClient // using oss client that already exists destination: async { return '' // return destination folder path, optional, '' is default value } filename: async { return fileoriginalname // return file name, optional, file.originalname is default value } stream: async { return filestream // compress strem in gzip } options: async { // read more https://www.npmjs.com/package/ali-oss#putstreamname-stream-options return contentLength: filesize headers: 'Content-Encoding': gzip 'Expires': 3600000 // in ms }
😘 Full Examples
Full examples for using multer-oss with express, multer
const bodyParser = const express = const http = const multer = const OSSStorage = const zlib = const app = const server = httpconst storage = oss: // required region: 'oss-region' internal: false accessKeyId: 'access-key-id' accessKeySecret: 'access-key-secret' bucket: 'bucket' // you could using all oss option in ali-oss pacakge destination: async { return '' // return destination folder path, optional, '' is default value } filename: async { return fileoriginalname // return file name, optional, file.originalname is default value } stream: async { return filestream // compress strem in gzip } options: async { return contentLength: filesize headers: 'Content-Encoding': gzip 'Expires': 3600000 // in ms }appappapp // for more multer usage, you could refrence multer documentappappserver