# multer-proxy-storage-engine

> Forward multipart/form-data file upload into a remote server.

Latest version **1.1.2** (published 2018-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install multer-proxy-storage-engine
pnpm add multer-proxy-storage-engine
yarn add multer-proxy-storage-engine
bun add multer-proxy-storage-engine
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2018-11-28 |
| First published | 2018-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | John Kim |
| Maintainers | johnkimdev |

## Links

- npm: https://www.npmjs.com/package/multer-proxy-storage-engine
- Repository: https://github.com/JohnKimDev/multer-proxy-storage-engine
- Issues: https://github.com/JohnKimDev/multer-proxy-storage-engine/issues
- npm.io page: https://npm.io/package/multer-proxy-storage-engine

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.18.0
- [form-data](https://npm.io/package/form-data.md) ^2.3.2
- [concat-stream](https://npm.io/package/concat-stream.md) ^1.6.2

## Recent versions

- 1.1.2 (latest) — 2018-11-28
- 1.1.1 — 2018-11-28
- 1.1.0 — 2018-11-28
- 1.0.1 — 2018-11-28
- 1.0.0 — 2018-11-28

## README

# Multer Proxy Storage Engine

This is a custom multer storage engine that proxy the received file into a remote server.
The proxy is forwarded as multipart/form-data.

## Install

```
npm install --save multer multer-proxy-storage-engine
```

## Usage

In this example we are forwarding user uploaded file into remote server http://www.example.com/upload, with the file
identified with the parameter 'file'.

Axios (https://www.npmjs.com/package/axios)[https://www.npmjs.com/package/axios] library is used for proxy request.
multer-proxy-storage-engine can foward all options for Axios request (https://www.npmjs.com/package/axios#request-config)[https://www.npmjs.com/package/axios#request-config]  

``` javascript
const multer = require('multer')
const multerProxyStorage = require('multer-proxy-storage-engine')

this.routePost('/uploadFile',
  (req, res, next) => {
    multer({
      storage: multerProxyStorage(
        {
          url: 'http://www.example.com/upload',   // REQUIRED
          method: 'post',           // OPTIONAL (if not set, deafult value is 'post') 
          fileParamName: 'file'     // OPTIONAL (if not set, deafult value is 'file') - this is a outgoing proxy file param name 
          timeout: 5000             // in ms, OPTIONAL (if not set, deafult value is 5000)
          // **** in addtion, you can set all (Axios configurations)[https://www.npmjs.com/package/axios#request-config] here 
        }),
      preservePath: true
    }).array('file')(req, res, next);   // 'file' is a incoming request param name for the multer configuration
  }, (req, res, next) => {
    res.send('Success!')
  })
```
Or it can be used as following

``` javascript
const multer = require('multer')
const multerProxyStorage = require('multer-proxy-storage-engine')
const upload = multer({
  storage: multerProxyStorage(
    {
      url: 'http://www.example.com/upload',   // REQUIRED
      method: 'post',           // OPTIONAL (if not set, deafult value is 'post') 
      fileParamName: 'file',    // OPTIONAL (if not set, deafult value is 'file') - this is a outgoing proxy file param name
      timeout: 5000,            // in ms, OPTIONAL (if not set, deafult value is 5000)
      // **** in addtiona, you can set all (Axios configurations)[https://www.npmjs.com/package/axios#request-config] here 
      headers: {'X-Requested-With': 'XMLHttpRequest'}   // an example of Axios configuration usage
    }),
  preservePath: true
}).array('file'); // NOTE: you can use .single('file') instead of .array('file') if you are expecting only one file
    
upload(req, res, (err, resData) => {
  if (err instanceof multer.MulterError) {
    // A Multer error occurred when uploading.  (https://github.com/expressjs/multer/blob/master/lib/multer-error.js)[https://github.com/expressjs/multer/blob/master/lib/multer-error.js]

    res.send('Multer ERROR');
    console.error(err);
  } else if (err) {
    // An unknown error occurred when uploading.
    res.send('Unknown ERROR');
    console.error(err);
  } else {
    res.send('SUCCESS');
    console.log(resData);
  }
});
```

## License
Multer-Proxy-Storage-Engine is released under the [MIT](License) license.

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