3.0.0 • Published 8 months ago

http-server-upload v3.0.0

Weekly downloads
12
License
MIT
Repository
github
Last release
8 months ago

http-server-upload

NPM version Downloads

NPM

This is a simple zero-configuration command-line http server which provides a lightweight interface to upload files.

By default files are uploaded to the current working directory.

Optionally a token may be used to protect against unauthorized uploads.

Installation

Version 3 of http-server-upload requires Node.js 14.18 or higher.

npm install --global http-server-upload

This will install http-server-upload globally so that it may be run from the command line.

Usage

http-server-upload [arguments] [uploadRootPath]

[uploadRootPath] defaults to the current working directory (./).

Other options can be set using environment variables.

When the server is running you can visit http://localhost:8080/ to get the upload form.

If the desired port is already in use, the port will be increased automatically until the next free port is found. This can be disabled, see below.

Attention: Already existing files will be overwritten on upload.

Arguments and environment variables

The optional configuration is done by command line arguments or environment variables.
If both are used, the arguments have higher priority and the value from the corresponding environment variable will be ignored.

ArgumentVariableDescriptionDefault
--portPORTThe port to use.8080
--upload-dirUPLOAD_DIRThe directory where the files should be uploaded to. This overrides the uploadRootPath argument.uploadRootPath argument or the current working directory
--upload-tmp-dirUPLOAD_TMP_DIRTemp directory for the file upload.The upload directory.
--max-file-sizeMAX_FILE_SIZEThe maximum allowed file size for uploads in Megabyte.200
--tokenTOKENAn optional token which must be provided on upload.Nothing
--path-regexpPATH_REGEXPA regular expression to verify a given upload path. This should be set with care, because it may allow write access to outside the upload directory./^[a-zA-Z0-9-_/]*$/
--disable-auto-portDISABLE_AUTO_PORTDisable automatic port increase if the port is nor available.Not set.
--enable-folder-creationENABLE_FOLDER_CREATIONEnable automatic folder creation when uploading file to non-existent folder.Not set.
--index-fileINDEX_FILEUse a custom html file as index instead of the default internal index. If used, the form fields need to have the same names as in the original index.Not set.
--help, -hShow some help text

Examples:

PORT=9000 UPLOAD_DIR=~/uploads/ UPLOAD_TMP_DIR=/tmp/ TOKEN=my-super-secret-token http-server-upload

http-server-upload --port=9000 --upload-dir="c:\users\peter\Path With Whitespaces\"

PORT=9000 http-server-upload --disable-auto-port --enable-folder-creation ./

Uploads from the command line

If the http-server-upload is running, you may also upload files from the command line using curl:

curl -F "uploads=@my-file.txt" http://localhost:8080/upload

Advanced example with multiple files, an upload path and a required token:

curl \
  -F "uploads=@my-file.txt" \
  -F "uploads=@my-other-file.txt" \
  -F "path=my/dir" \
  -F "token=my-super-secret-token" \
  http://localhost:8080/upload

Example for uploading content from a pipe:

cat my-file.dat \
  | curl -F "uploads=@-;filename=my-file.dat;type=application/octet-stream" \
  http://localhost:8080/upload

Notice the required filename and type defintions for uploading piped data.
The type is the mime type of the data to upload.

License

MIT license

Copyright (c) 2019-2023 Peter Müller peter@crycode.de https://crycode.de

3.0.0

8 months ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.2

1 year ago

2.1.2

1 year ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.0

3 years ago

1.0.0

5 years ago