Giter Site home page Giter Site logo

alphakevin / unoconv-server Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 15.0 191 KB

A simple RESTful server for converting documents using unoconv

License: MIT License

JavaScript 97.85% Shell 0.39% Dockerfile 1.76%
unoconv restful convert converting-documents pdf

unoconv-server's Introduction

unoconv-server

A simple RESTful server for converting documents using unoconv

Install

unoconv is required for converting documents

# apt-get install unoconv
npm install unoconv-server

Usage

Start a server in command-line:

./unoconv-server start

Get command line help

./unoconv-server --help
unoconv-server, a simple RESTful server for converting documents
  please visit https://github.com/alphakevin/unoconv-server

usage: unoconv-server <command> <options>

commands:
  start [<hostname>[:<port>]]  start the server, default to localhost:4000
  help converter             get converter help

options:
  -h, --help                 print this help message

Use in your application

const expores = require('express');
const unoconv = require('unoconv-server');

const app = express();
app.use('/unoconv', unoconv());
// ... your own express routes
app.listen(3000);

Converter

When the server starts, it will start a listener for better performance, the listener will be stopped together with the server.

The server provides a similar interface like unoconv, you can simply remove -- or - and use / instead of white-space between the arguments, all after /convert.

POST /convert/format/<format>[/output/<filename>] HTTP/1.1

You can upload file by either of the following method:

  • multipart/form-data upload with a file field of the file to be converted.
  • RAW upload a file in HTTP body with Content-Type and Content-Disposition header provided.

If the /output/<value> option is provided, the Content-Disposition header will contain the new filename.

The converted document will be directly output from the HTTP response body.

Environment Variables

Name Description
HOSTNAME For server listening hostname
PORT For server listening port

Example

Visit http://127.0.0.1:4000/help, or get help in command-line:

./unoconv-server help converter

Here we use cURL for examples.

Uploading with multipart/form-data

curl -F [email protected] http://127.0.0.1:4000/convert/format/pdf/output/newname.pdf > result.pdf

Uploading RAW binary data

curl -X POST \
-T "example.docx" \
-H "Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document" \
-H "Content-Disposition: attachment; filename="example.docx"" \
http://127.0.0.1:4000/convert/format/pdf/output/newname.pdf > result.pdf

Converting options:

  /e, /export/<value>     set export filter options
  /f, /format/<value>     specify the output format
  /F, /field/<value>      replace user-defined text field with value
  /i, /import/<value>     set import filter option string
  /o, /output/<value>     output basename, filename or directory
      /password/<value>   provide a password to decrypt the document

Playing with Docker

unoconv-server can start from docker without source code or npm installed:

docker run -d -p 4000:4000 --name unoconv alphakevin/unoconv-server

Notice

This is a simple server and it does not include authorization method, please take your own risk if you want to deploy it public directly.

export, field, import, password options are not tested, it just pass them to unoconv.

Related

  • unoconv A node.js wrapper for converting documents with unoconv.
  • unoconv2 A version forked from node-uniconv which has better error handling.
  • tfk-api-unoconv Unoconv as a webservice together with docker image.
  • filepreview File preview image as a service

License

MIT

unoconv-server's People

Contributors

alphakevin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

unoconv-server's Issues

Unhandled 'error' event spawn unoconv ENOENT

unoconv-server username$ ./unoconv-server start

starting unoconv listener...

events.js:182
throw er; // Unhandled 'error' event
^

Error: spawn unoconv ENOENT
at exports._errnoException (util.js:1024:11)

Getting this error while starting server in OSX yosemite

Error: Unable to connect or start own listener. Aborting

I wanted to test how stable this is for a project of mine with a high workload
So I started 5 while true loops with curl in it to see how unoconv-server handles this.

At first everything seemed fine, but after a few minutes I started seeing these error messages

unoconv --format pdf --output /tmp/dbfa20ed-581d-4f97-8355-6477d9576716.pdf /tmp/dbfa20ed-581d-4f97-8355-6477d9576716.ods
Error: Failed to connect to /usr/lib/libreoffice/program/soffice.bin (pid=27433) in 6 seconds.
Connector : couldn't connect to socket (Connection refused)
Error: Unable to connect or start own listener. Aborting.

    at ChildProcess.handler.on (/home/christopher/Projects/node_modules/unoconv-server/lib/converter.js:148:25)
    at ChildProcess.emit (events.js:188:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
Error: Failed to connect to /usr/lib/libreoffice/program/soffice.bin (pid=27449) in 6 seconds.
Connector : couldn't connect to socket (Connection refused)
Error: Unable to connect or start own listener. Aborting.

    at ChildProcess.handler.on (/home/christopher/Projects/node_modules/unoconv-server/lib/converter.js:148:25)
    at ChildProcess.emit (events.js:188:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
Error: Failed to connect to /usr/lib/libreoffice/program/soffice.bin (pid=27450) in 6 seconds.
Connector : couldn't connect to socket (Connection refused)
Error: Unable to connect or start own listener. Aborting.

    at ChildProcess.handler.on (/home/christopher/Projects/node_modules/unoconv-server/lib/converter.js:148:25)
    at ChildProcess.emit (events.js:188:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
POST /convert/format/pdf
[ '--format', 'pdf' ] { format: 'pdf' } '/tmp/26f0beb2-fd2e-45d0-8502-beb0d2d63354.pdf'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.