1.0.2 • Published 3 years ago

rwserve-multi-upload v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago
Open Source RWSERVE plugin

Multi Upload

Accept multipart/form-data

Motivation

Uploading binary files is not possible with typical HTML forms because content type x-www-form-urlencoded only works for text data.

Content type multipart/form-data was created to handle binary files.

Properly crafted HTML forms with enctype=multipart/form-data and an input type=file element are the solution.

When a POST request is received by the RWSERVE server, multipart data is parsed and staged to MultipartEntry objects. This staging area is accessible to plugin developers.

The rwserve-multi-upload plugin demonstrates how to use this mechanism to save uploaded files to the server.

Customization

This plugin is open source and can be modified or enhanced to perform tasks such as these:

  • Saving binary data to a database.
  • Receiving encrypted security credentials and acting upon them.
  • Working with binary data without the need for base64 encoding schemes.

Download

The plugin module is available from NPM . Before proceeding, you should already have Node.js and RWSERVE configured and tested.

This module should be installed on your web server in a well-defined place, so that it can be discovered by RWSERVE. The standard place for public domain plugins is /srv/rwserve-plugins.

Configuration is Everything

Make the software available by declaring it in the plugins section of your configuration file. For detailed instructions on how to do this, refer to the plugins documentation on the Read Write Tools HTTP/2 Server website.

TL;DR

The config settings can be adjusted using this guidance.

content-length-limit is a positive integer. This is the maximum size of the request body that the server will handle. Requests larger than this will be rejected with status code 413. Keeping this low prevents bad actors from dropping payload bombs on the server.

maxbytes is a positive integer. This is the maximum size of any one file being uploaded. This value should be less than or equal to the content-length-limit value.

destination-directory is the where the uploaded files will be saved.

Cookbook

A full configuration file with typical settings for a server running on localhost port 7443, is included in this NPM module at etc/multi-upload-config. To use this configuration file, adjust these variables if they don't match your server setup:

Usage

Server

Start the server using the configuration file just prepared. Use Bash to start the server in the background, like this:

Deployment

Once you've tested the plugin and are ready to go live, adjust your production web server's configuration in /etc/rwserve/rwserve.conf and restart it using systemd . . .

. . . then monitor its request/response activity with journald.

Prerequisites

This is a plugin for the Read Write Tools HTTP/2 Server, which works on Linux platforms.

Review

License

The rwserve-multi-upload plugin is licensed under the MIT License.

Availability