Getting Started
Installation
$ npm install librarian
Server Usage
const librarian = require('librarian')
let app = librarian()
app.listen(8888)
See configuration for more options.
Client Usage
Request JS
const request = require('request')
const fs = require('fs')
let fileStream = fs.createReadStream(__dirname + '/test-image.png')
fileStream.pipe(request.post('http://localhost:8888'))
Browser Form
<form method="POST" action="http://localhost:8888" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit">Upload</button>
</form>
POST Response
{
"id": "e10a0a08-1688-4dff-8a26-fea6ff32e2d4",
"size": 125731,
"name": "test-image.png",
"mimeType": "image/jpeg"
}
Image Retrieval
Browser
<!-- normal -->
<img src="http://localhost:8888/e10a0a08-1688-4dff-8a26-fea6ff32e2d4">
<!-- resized -->
<img src="http://localhost:8888/e10a0a08-1688-4dff-8a26-fea6ff32e2d4?width=50">
<!-- resized -->
<img src="http://localhost:8888/e10a0a08-1688-4dff-8a26-fea6ff32e2d4?height=50">
<!-- resized -->
<img src="http://localhost:8888/e10a0a08-1688-4dff-8a26-fea6ff32e2d4?max=50">
RequestJS
const request = require('request')
const fs = require('fs')
let fileStream = fs.createWriteStream(__dirname + '/test-image.png')
request
.post('http://localhost:8888/e10a0a08-1688-4dff-8a26-fea6ff32e2d4')
.post(fileStream)