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.
npm install --global http-server-upload
This will install
http-server-uploadglobally so that it may be run from the command line.
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 variablesThe 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.
| Argument | Variable | Description | Default | |---|---|---|---| |
PORT| The port to use. |
UPLOAD_DIR| The directory where the files should be uploaded to. This overrides the
uploadRootPathargument or the current working directory | |
UPLOAD_TMP_DIR| Temp directory for the file upload. | The upload directory. | |
MAX_FILE_SIZE| The maximum allowed file size for uploads in Megabyte. |
TOKEN| An optional token which must be provided on upload. | Nothing | |
PATH_REGEXP| A 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. |
DISABLE_AUTO_PORT| Disable automatic port increase if the port is nor available. | Not set. | |
ENABLE_FOLDER_CREATION| Enable automatic folder creation when uploading file to non-existent folder. | Not set. | |
-h| | Show some help text | |
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 lineIf the
http-server-uploadis running, you may also upload files from the command line using
curl -F "email@example.com" http://localhost:8080/upload
Advanced example with multiple files, an upload path and a required token:
curl \ -F "firstname.lastname@example.org" \ -F "email@example.com" \ -F "path=my/dir" \ -F "token=my-super-secret-token" \ http://localhost:8080/upload
Copyright (c) 2019-2023 Peter Müller https://crycode.de