File Sharing with File Browser

1 minute read

Previously, I use cowtransfer to share files with our partners, thanks to cowtransfer-uploader, it is very convenient for automation, this changed recently, the uploader stops working after cowtransfer upgraded its service.

I found File Browser is a very similar to cowtransfer, so I make it part of my automation procedure.

Run File Browser as Docker Service

File Browser is a web service, which can be managed with docker, the only thing need to do is to create an empty file named filebrowser.db:

touch filebrowser.db

and a docker-compose.yml:

version: '3.5'

services:
  filebrowser:
    container_name: filebrowser
    image: filebrowser/filebrowser:latest
    restart: unless-stopped
    user: "${UID}:${GID}"
    ports:
        - "8080:80"
    volumes:
      - ${PWD}/share:/srv
      - ${PWD}/filebrowser.db:/database.db
docker-compose up -d

Note that, alpine version docker image does not have filebrowser command, while linuxserver version has.

$ docker exec -it filebrowser filebrowser --help
$ docker exec -it filebrowser filebrowser config init

Upload Files

Using scp or rsync will be ok, it will show up in the webUI, another way to do this is using its undocumented API, I have not tested.

Share Files

File Sharing can be done with webUI, but for automation, we need to use commands or API. Looking into its code base, I find File Browser supports it by POST, ntaapp’s comment helps me a lot, and hacdias’s comment about Authorization: Bearer {token} is outdated.

This is what I did for creating a share and get its URL:

# Get login token
token=$(curl -sX POST http://101.35.170.171:8080/api/login -d '{ "username": "admin", "password": "admin" }')

# Share a file and get hash value
curl -sX POST http://101.35.170.171:8080/api/share/test.png \
     -H 'Accept: application/json' -H "X-Auth: ${token}" \
     -d '{ "expires": "30", "unit": "day" }' | jq -r '.hash'

# List all shares
curl -X GET http://101.35.170.171:8080/api/shares -H 'Accept: application/json' -H "X-Auth: ${token}"