Auto-scale Picture

Hello NextClouders,

I have the following idea and would like to ask for the right way to do:

In a directory in the NC share I save photos from the mobile phone. Now I want to run a small (Python-) script on the NC server, which scales the image down using imagemagick. Then I can use it for mail attachments and so on.
Two questions arise:

  1. When is the upload of the image complete? Can my script get a trigger from NC for this?
  2. It is not sufficient that the new image exists in the file system. How do I get the new image automatically into the NC share (register the file in the NC-database)?

Do we have to develop a real plug-in? Or is there already a solution for the idea?

Thanks and greetings,

Boris

Check this out “Pass files on to external scripts depending on a defined set of rules”: https://apps.nextcloud.com/apps/workflow_script

Also you can tag file first via this app https://apps.nextcloud.com/apps/files_automatedtagging and then use workflow app from above with corresponding tag.

I did not catch this. Could you please describe use case?

Hej gas85,

thank you very much for this hint. It seems to be the right solution for my request and I will soon start to experiment!

To explain the second question:
If a new file is created in nextclout/data/user/files (by hand or by running a script) on the NC server, it is not automatically being presented in NC’s webfrontend or to any dav-client. Imho, it needs to be registered in the database. So, how can that be done?
But eventually, the workflow app will do it…
Regards,
Boris

1 Like

It is not recommended way of working with NC, but you need to run “scan” command to rescan files under the path, or whole NC filesystem:

sudo -u www-data php occ files:scan --path="user_id/files/mount_name/path"

E.g.

sudo -u www-data php occ files:scan --path="/alice/files/Music"

–> Doku: https://docs.nextcloud.com/server/15/admin_manual/configuration_server/occ_command.html#scan

My sgesstion is to added some local folder as Nextcloud external storage and work with your scripts direct there. Afterwards ether run rescan command, or do periodical external shares rescan. I wrote small script for a cron job, to do periodically external shares rescan. Will also generate small report in your logs:
image