The service provides a convenient means of sharing files without the necessity for user accounts or a complicated setup. The accompanying code includes the server, encompassing everything you need to create your own instance.
Feature highlights
- Basic Authentication
- Anonymous Uploads
- File Expiration
- Burn After Reading
- QR code Generator
- Command Line Interface (CLI)
- Built-in TLS Server
Run Backend Service Locally
# Clone the project
$ git clone https://github.com/robatipoor/pf
# Build the backend binary
$ cargo build --bin api --release
# Run the backend on address 127.0.0.1:8080
$ ./target/release/api --settings api/settings/base.toml
Run Backend Service via Docker
# Build docker image
$ docker build -t pf-api:latest -f api/Dockerfile .
# Run Docker container on address 0.0.0.0:8080
$ docker run --name pf-api --rm -p 8080:8080 \
-e PF__SERVER__HOST='0.0.0.0' -d pf-api:latest
# Alternatively, you can pull the image from the github registry and run container
$ docker run --name pf-api --rm -p 8080:8080 \
-e PF__SERVER__HOST='0.0.0.0' -d ghcr.io/robatipoor/pf-api:latest
How to Use
# Ping the server.
$ curl -X GET http://127.0.0.1:8080/healthz
# Upload a file and retrieve the corresponding download URL.
$ curl -s -F "file=@{file_name}" 127.0.0.1:8080/upload | jq -r '.url'
# Download a file.
$ curl -o {file_name} http://127.0.0.1:8080/{code}/{file_name}
# Upload a file with basic authentication.
$ curl -u username:password -F "file=@{file_name}" 127.0.0.1:8080/upload
# Download a file with basic authentication.
$ curl -o {file_name} -u username:password http://127.0.0.1:8080/{code}/{file_name}
# Upload a file and then display the QR code.
$ curl -s -F "file=@{file_name}" 127.0.0.1:8080/upload | jq -r '.qrcode' | base64 -d; echo
# Upload a file with an expiration time of 100 seconds (default value specified in settings file).
$ curl -F "file=@{file_name}" 127.0.0.1:8080/upload\?expire_secs=100
# Upload a file with a restriction on the number of downloads.
$ curl -F "file=@{file_name}" 127.0.0.1:8080/upload\?max_download=10
# Upload a file and specify the minimum code length in the URL path as 5 (default value specified in settings file).
$ curl -F "file=@{file_name}" 127.0.0.1:8080/upload\?code_length=5
# Upload a file and prevent manual deletion until expiration.
$ curl -F "file=@{file_name}" 127.0.0.1:8080/upload\?delete_manually=false
# Get metadata for a file.
$ curl -X GET http://127.0.0.1:8080/info/{code}/{file_name}
# Delete a file.
$ curl -X DELETE http://127.0.0.1:8080/{code}/{file_name}
Backend settings
# api/settings/base.toml
# Maximum upload size in bytes
max_upload_bytes_size = 1000_000_000 # 1GB
# Default code length in the url
default_code_length = 3
# Default expiration time in seconds
default_expire_secs = 7200
# Server configuration section
[server]
# Communication protocol (e.g., "http" or "https")
schema = "http"
# Host IP address for the server
host = "127.0.0.1"
# Port number for the server
port = 8080
# TLS key file path
file_tls_key_path = "key.pem"
# TLS certificate file path
file_tls_cert_path = "cert.pem"
# File system configuration section
[fs]
# Base directory for file system operations
base_dir = "tmp/fs"
# Database configuration section
[db]
# Path directory to the database file
path_dir = "tmp/db"
Override settings with environment variables
export PF__SERVER__PORT=8080
export PF__SERVER__HOST=127.0.0.1
PastFile Command Line Interface
# Clone the project
$ git clone https://github.com/robatipoor/pf
# Build the CLI tool
$ cargo build --bin cli --release
# Upload a file and retrieve the corresponding download URL.
$ ./target/release/cli --server-addr "http://localhost:8080" \
upload --source-file ~/example-file.txt --progress-bar
# Upload a file with basic authentication and progress bar option.
$ ./target/release/cli --server-addr "http://localhost:8080" \
--auth "username:password" upload --source-file ~/example-file.txt
# Upload a file with an expiration time of 10 minutes.
$ ./target/release/cli --server-addr "http://localhost:8080" \
upload --expire "10 minute" --source-file ~/example-file.txt
# Upload a file and then display the QR code.
$ ./target/release/cli --server-addr "http://localhost:8080" \
upload --source-file ~/example-file.txt --out qr-code
# Download a file with progress bar option.
$ ./target/release/cli --server-addr "http://localhost:8080" \
download --destination-dir ~/example-dir/ --url-path "{code}/{file_name}" --progress-bar
# Download a file.
$ ./target/release/cli --server-addr "http://localhost:8080" \
download --destination-dir ~/example-dir/ --url-path "{code}/{file_name}"
# Get metadata for a file.
$ ./target/release/cli --server-addr "http://localhost:8080" \
info --url-path "{code}/{file_name}"
# Delete a file.
$ ./target/release/cli --server-addr "http://localhost:8080" \
delete --url-path "{code}/{file_name}"
Run tests
./test.sh
Todo list
-
Implement front-end app
-
Build-in support for encryption in CLI
Check code formatting and typo at commit time
cp ./scripts/git-hooks/* ./.git/hooks/
License
Licensed under either of
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contributing
Contributors are welcome, please fork and send pull requests! If you find a bug or have any ideas on how to improve this project please submit an issue.
See CONTRIBUTING.md.