Skip to content

A lightweight, unofficial file retrieval server powered by the Filen.io SDK. Designed for public, read-only access to files such as images, PDFs, and videos.

License

Notifications You must be signed in to change notification settings

desw0lf/filen-public-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

preview

Filen Public Express

Serve static files publicly via filen.io buckets

NPM lang license

filen Β Β Β  express


πŸ”— Table of Contents

πŸ“ Overview

A lightweight, unofficial static file server powered by the Filen.io SDK. Designed for public, read-only access to files such as images, PDFs, and videos.

πŸ‘Ύ Features

  • Serve files from either all public buckets β€” or via one specific master bucket1
  • Supports server-wide CORS configuration, and JSON CORS configurations23 inside each bucket - mimics AWS S3 CORS configuration structure (example)
  • Supports file downloads4 via search parameters in GET requests (e.g. .../file.jpg?dl=1)
  • Supports file ignores5 (e.g. ["secret.json", { endsWith: ".key" }])

πŸš€ Getting Started

β˜‘οΈ Prerequisites

Node.js version:

  • Minimum: v22.6.0
  • Preferred: v23.7.0

βš™οΈ Installation

npm

In your project, install using NPM:

npm install filen-public-express

πŸ€– Usage

  1. Create a bucket on Filen.io starting with public_ (e.g. public_myimages)
  2. Initialize the server:
import { FilenPublicExpress } from "filen-public-express";

const server = new FilenPublicExpress({
  user: {
    sdkConfig: {
      email: "[email protected]",
      password: "yourfilenpassword"
    }
  }
});

await server.start();
  1. Start the server:
node server.js

You should now be able to access the files in your public buckets in your browser. (e.g. http://localhost:1700/myimages/mydog.jpg)

Note

Only files in public buckets (with public_ prefix) can be accessed. (e.g. public_myimages) The prefix is omitted in the URL pathname.

πŸ”§ Configuration

config Options

Option Type Default Description
downloadFileParam string | null | undefined | false "dl" 4Used as query param (e.g. .../file.pdf?dl=1) that allows downloading files instead of displaying them inline
masterBucket string | undefined - 1Name of the singular bucket that the server will expose publicly (setting this value will remove the ability for the server to expose other buckets)
ignoreList IgnoreRule[] - 5List of ignore rules for files/keys (e.g. ["secret.json", { endsWith: ".key" }])
corsBucketFileName string | undefined .filen-public.json 2Name for individual JSON CORS configurations inside the bucket
corsBucketCacheTTLMinutes number | undefined 10 Cache duration for CORS configurations
corsBucketCachePurgeUrl string | undefined - URL to purge CORS cache (e.g. "/purge-cors-cache")
expressTrustProxy boolean | number | string | string[] false Express.js trust proxy setting

corsOptions

Option Type Default Description
methods "GET" "GET" Only GET method is supported
origin string | string[] "*" Allowed Origins/Referers

.filen-public.json Configuration

3Place this file inside your bucket to configure CORS settings:

[
  {
    "AllowedMethods": ["GET"],
    "AllowedOrigins": ["https://example.com"]
  }
]

Bucket File Configuration

Important

Must be an array, only "GET" method supported, origin "*" is used to allow all. Mimics AWS S3 CORS configuration structure.

⌨️ Examples

Examples can be found in the examples folder.

πŸ› οΈ Troubleshooting

.mp4 not playing inline/directly on iPhone/iPad browsers when using Cloudflare CDN

If you're serving .mp4 files through Cloudflare and they are not playing inline in iOS browsers, this is likely due to Cloudflare's caching or compression settings. Follow these steps to bypass .mp4 Cloudflare cache for User Agents that include iPhone/iPad:

  1. Go to Caching > Cache Rules.
  2. Add the following condition:
(http.request.uri.path.extension in {"mp4"}) and (http.user_agent contains "iPad" or http.user_agent contains "iPhone" or http.user_agent contains "Macintosh")
  1. Set the action to "Bypass cache".

(visual config example)

❕ Disclaimer

This project is not affiliated with or endorsed by Filen.io. It is provided as is, without any warranties or guarantees. The author assumes no responsibility for any issues, including but not limited to data privacy, security risks, or legal compliance arising from the use of this software. Use at your own risk.

πŸŽ— License

Distributed under the AGPL-3.0 License. See LICENSE for more information.

πŸ™Œ Acknowledgments

This project:

About

A lightweight, unofficial file retrieval server powered by the Filen.io SDK. Designed for public, read-only access to files such as images, PDFs, and videos.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published