Gathering detailed insights and metrics for @simagic/multer-ali-oss
Gathering detailed insights and metrics for @simagic/multer-ali-oss
Gathering detailed insights and metrics for @simagic/multer-ali-oss
Gathering detailed insights and metrics for @simagic/multer-ali-oss
npm install @simagic/multer-ali-oss
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
5 Commits
1 Forks
1 Watchers
1 Branches
2 Contributors
Updated on Jun 25, 2024
Latest Version
1.0.1
Package Id
@simagic/multer-ali-oss@1.0.1
Unpacked Size
65.85 kB
Size
18.05 kB
File Count
8
NPM Version
10.5.0
Node Version
18.20.2
Published on
Jun 25, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Streaming multer storage engine for ali-oss.
This project is mostly an integration piece for existing code samples from Multer's storage engine documentation with a call to ali-oss as the substitution piece for file system.
1npm install --save @simagic/multer-ali-oss
1const express = require('express'); 2const multer = require('multer'); 3const OSS = require('ali-oss'); 4const { OSSStorage, AUTO_CONTENT_TYPE } = require('@simagic/multer-ali-oss') 5 6const store = new OSS({ 7 region: '<oss region>', 8 accessKeyId: '<Your accessKeyId>', 9 accessKeySecret: '<Your accessKeySecret>', 10 bucket: '<Your bucket name>' 11}); 12 13const upload = multer({ 14 storage: OSSStorage({ 15 oss: store, 16 bucket: '<Your bucket name>', // todo: Support different buckets instead of the default 17 metadata: function (req, file, cb) { 18 cb(null, {fieldName: file.fieldname}); 19 }, 20 key: function (req, file, cb) { 21 cb(null, 'simagic-cloud/' + Date.now().toString()) 22 } 23 // Direct parameters are also valid 24 acl: 'public-read', 25 }) 26}) 27 28// Example route for single file upload 29app.post('/upload', upload.single('file'), (req, res) => { 30 const file = req.file 31 // File uploaded successfully 32 console.log(req.file) 33 res.status(200).send('File uploaded successfully'); 34}); 35 36// Example route for multiple file upload 37app.post('/uploads', upload.fields([ 38 { name: 'avatar', maxCount: 1 }, 39 { name: 'photo', maxCount: 2} 40]), (req, res) => { 41 // Access text fields via req.body 42 console.log(req.body); 43 44 // Access uploaded files via req.files 45 console.log(req.files); 46 47 // Files uploaded successfully 48 res.status(200).send('Files uploaded successfully'); 49}); 50 51app.listen(port, () => { 52 console.log(`Server is running on port ${port}`); 53}); 54 55// ts 56// import { OSSStorage, AUTO_CONTENT_TYPE, OSSStorageEngine } from '@simagic/multer-ali-oss'; 57
Each file contains the following information exposed by @simagic/multer-ali-oss
:
Key | Description | Note |
---|---|---|
bucket | The bucket used to store the file | OSSStorage |
key | The name of the file | OSSStorage |
acl | Access control for the file | OSSStorage |
contentType | The mimetype used to upload the file | OSSStorage |
metadata | The metadata object to be sent to ali-oss | OSSStorage |
location | The ali-oss url to access the file | OSSStorage |
etag | The etag of the uploaded file in ali-oss | OSSStorage |
contentDisposition | The contentDisposition used to upload the file | OSSStorage |
storageClass | The storageClass to be used for the uploaded file in ali-oss | OSSStorage |
contentEncoding | The contentEncoding used to upload the file | OSSStorage |
hash | The hash of the file | MD5 |
Also include:
fieldname
originalname
encoding
mimetype
ACL values can be set by passing an optional acl
parameter into the @simagic/multer-ali-oss
object.
1const upload = multer({ 2 storage: OSSStorage({ 3 oss: store, 4 bucket: '<Your bucket name>', // todo: Support different buckets instead of the default 5 acl: 'public-read', 6 metadata: function (req, file, cb) { 7 cb(null, {fieldName: file.fieldname}); 8 }, 9 key: function (req, file, cb) { 10 cb(null, 'simagic-cloud/' + Date.now().toString()) 11 } 12 }) 13})
1const upload = multer({ 2 storage: OSSStorage({ 3 oss: store, 4 bucket: '<Your bucket name>', // todo: Support different buckets instead of the default 5 acl: 'public-read', 6 metadata: function (req, file, cb) { 7 cb(null, {fieldName: file.fieldname}); 8 }, 9 key: function (req, file, cb) { 10 cb(null, 'simagic-cloud/' + Date.now().toString()) 11 } 12 }) 13})
1const upload = multer({ 2 storage: OSSStorage({ 3 oss: store, 4 bucket: '<Your bucket name>', // todo: Support different buckets instead of the default 5 acl: 'public-read', 6 metadata: function (req, file, cb) { 7 cb(null, {fieldName: file.fieldname}); 8 }, 9 cacheControl: 'max-age=31536000', 10 key: function (req, file, cb) { 11 cb(null, 'simagic-cloud/' + Date.now().toString()) 12 } 13 }) 14})
1const upload = multer({ 2 storage: OSSStorage({ 3 oss: store, 4 bucket: '<Your bucket name>', // todo: Support different buckets instead of the default 5 acl: 'public-read', 6 metadata: function (req, file, cb) { 7 cb(null, {fieldName: file.fieldname}); 8 }, 9 contentType: AUTO_CONTENT_TYPE, 10 cacheControl: 'max-age=31536000', 11 key: function (req, file, cb) { 12 cb(null, 'simagic-cloud/' + Date.now().toString()) 13 } 14 }) 15})
You may also use a function as the contentType
, which should be of the form function(req, file, cb)
.
optional storageClass
optional contentDisposition
optional contentEncoding
No vulnerabilities found.
No security vulnerabilities found.