The issue you are facing: So this isn’t actually something I need help with, I just thought I’d share my solution to the issue. Feel free to move it if it belongs elsewhere.
I have a Brother scanner and until recently I was using its “Scan to Dropbox” feature to make scanning really easy. Since switching to Nextcloud I needed a solution. There’s a couple ways to skin that particular cat, but here’s what worked really well for me:
- Create a new SMB share of a sub-folder within your Nextcloud data directory. Yes, this means Nextcloud won’t see new files, we’ll tackle that later.
- Set up your scanner to upload to this new SMB share
- Create a file monitor for that folder that prompts Nextcloud to scan for new files.
In detail, here’s the (very few) changes I needed to make. Starting with a few new lines in
[brother-scan] path = /path/to/nextcloud/data/<username>/files/From_BrotherDevice # Whatever user Nextcloud sets as the owner of all files valid users = http public = no comment = Location for scans from Brother scanner printable = no writable = yes create mask = 0770
Restart your SMB server and set up scanning. None of this has to do with Nextcloud, just make sure it works first. You can replace this with other methods, e.g. FTP depending on what you got available.
Now we check for new files using a systemd path file
[Unit] Description=Monitor Nextcloud document scan folder [Path] PathChanged=/path/to/nextcloud/data/<username>/files/From_BrotherDevice
This file will now monitor just that folder. If changes are detected, it’ll run
/etc/systemd/system/scan-monitor.service which we’ll create next:
[Unit] Description=Trigger Nextcloud re-scan of document scan folder Requires=docker.service [Service] Type=oneshot ExecStart=docker exec --user www-data nextcloud-aio-nextcloud /var/www/html/occ files:scan -p <username>/files/From_BrotherDevice
In my example I’m actually running Nextcloud in a docker container, but you can make it even easier if you run on the host, just make sure to remove the
docker exec --user www-data nextcloud-aio-nextcloud part, adjust paths and you might want to run it as your
www-data user, e.g. by using
User=www-data for the unit (haven’t tested it though).
Anyway, hopefully this helps some people. It’s obviously not limited to scanning just incidentally the problem I wanted to solve.