This repo contains simple Koa.js REST API for file conversion using headless libreoffice
. For supported files list unoconv
is used.
- Clone this repo:
git clone [email protected]:lup-/unoconv-api.git
- Install dependencies:
npm install
- Run:
npm run server
Run image from Docker Hub
docker run -d -p 3000:3000 lup098/unoconv-lo-convert-api
- Create docker-compose.yml:
version: "3.7"
services:
converter:
image: lup098/unoconv-lo-convert-api
ports:
- 3000:3000
- Run docker-compose:
docker-compose up -d converter
Make GET request to http://localhost:3000/formats
curl -X GET --location "http://localhost:3000/formats"
To convert document to another format, submit file
field in POST request to http://localhost:3000/convert/:format.
Where :format
is extension of target file. On successful conversion new file will be downloaded.
Convert file testDoc.docx
from current folder to text:
curl -X POST "http://localhost:3000/convert/txt" -F "[email protected]"
Convert file testDoc.pdf
from current folder to text:
curl -X POST "http://localhost:3000/convert/html" -F "[email protected]"
let file = fileInput.files[0];
let requestData = new FormData();
requestData.append('file', file);
let {data} = await axios.post('http://localhost:3000/convert/txt',
requestData,
{ headers: {'Content-Type': 'multipart/form-data'} });
let fileText = data;