# multer-ali-oss

> Multer Storage for Aliyun OSS

Latest version **0.0.3** (published 2016-07-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install multer-ali-oss
pnpm add multer-ali-oss
yarn add multer-ali-oss
bun add multer-ali-oss
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-07-04 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Yishi Guo |
| Maintainers | e10101 |
| Keywords | express, multer, aliyun, oss |

## Links

- npm: https://www.npmjs.com/package/multer-ali-oss
- Repository: https://github.com/e10101/multer-ali-oss
- Issues: https://github.com/e10101/multer-ali-oss/issues
- npm.io page: https://npm.io/package/multer-ali-oss

## Dependencies (2)

- [crypto](https://npm.io/package/crypto.md) 0.0.3
- [ali-oss](https://npm.io/package/ali-oss.md) ^4.4.3

## Recent versions

- 0.0.3 (latest) — 2016-07-04
- 0.0.2 — 2016-05-26
- 0.0.1 — 2016-05-26

## README

# multer-ali-oss
Streaming multer storage engine for Aliyun OSS.

## Installation
```sh
npm install --save multer-ali-oss
```

## Usage

```javascript
var multer  = require('multer');
var aliOssStorage = require('multer-ali-oss');

var upload = multer( {
  storage: aliOssStorage({
    config: {
      region: '<region>',
      accessKeyId: '<accessKeyId>',
      accessKeySecret: '<accessKeySecret>',
      bucket: '<bucket>',
    },
    filename: function (req, file, cb) {
      cb(null, file.fieldname + '-' + Date.now())
    }
  })
}).single('upload');

router.post('/', function(req, res, next) {
  upload(req, res, function (err) {
    if (err) {
      // handle error
    }

    var result = {
      "uploaded": 1,
      'name': req.file.name,
      "url": req.file.url
    };

    res.render('result', {});
  });
});
```


### File information

Each file contains the following information:

Key | Description | Note
--- | --- | ---
`fieldname` | Field name specified in the form |
`originalname` | Name of the file on the user's computer |
`encoding` | Encoding type of the file |
`mimetype` | Mime type of the file |
`size` | Size of the file in bytes |
`name` | Name of the file | `AliOssStorage`
`url` | Url of the file on OSS | `AliOssStorage`

## Notice
As the `ali-oss`, one of the dependencies, using the ES6 features. The app depends on this package should start with `--harmony`.

### AliOssStorage

You need to specify the `region`, `accessKeyId`, `accessKeySecret`, `bucket`.

```javascript
var aliOssStorage = require('multer-ali-oss');
var storage = aliOssStorage({
  config: {
    region: '<region>',
    accessKeyId: '<accessKeyId>',
    accessKeySecret: '<accessKeySecret>',
    bucket: '<bucket>',
  },
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now())
  }
})

var upload = multer({ storage: storage })
```

There is one option available, `filename`. It is a function that determine where the file should be stored.

`filename` is used to determine what the file should be named. If no filename is given, each file will be given a random name that doesn't include any file extension.

---
_Source: https://npm.io/package/multer-ali-oss · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
