1.0.0 • Published 4 years ago

bono-file v1.0.0

Weekly downloads
13
License
MIT
Repository
github
Last release
4 years ago

bono-file

npm i bono-file

Bono file server

Create server

const http = require('http');
const { FileBundle } = require('bono-file');

const PORT = process.env.PORT || 3000;

const bundle = new FileBundle({ dataDir: '/path/to/data/dir' });
const server = http.createServer(bundle.callback());

server.listen(PORT, () => console.info('Listening at', PORT));

Upload

<form method="POST" action="http://localhost:3000/upload?bucket=/foo" enctype="multipart/form-data">
  <input type="file" name="file" multiple>

  <input type="submit">
</form>

Get file

let file = 'change this to filename';

await fetch(`/files/foo/${file}`); // get as mimetype
await fetch(`/files/foo/${file}?attachment=1`); // download with default name
await fetch(`/files/foo/${file}?attachment=1&name=foo.txt`); // download with specified name

Use middlewares

const http = require('http');
const Bundle = require('bono');

const { FileSystem, upload, download } = require('bono-file');

const PORT = process.env.PORT || 3000;

const fs = new FileSystem({ dataDir: '/path/to/data/dir' });

const bundle = new Bundle();

bundle.use(upload({ fs }));
bundle.use(download({ fs }));

const server = http.createServer(bundle.callback());

server.listen(PORT, () => console.info('Listening at', PORT));
1.0.0

4 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago