Workflow or plugin for deleting files after download

Hello everyone, this is my first post, I hope to be in the right section :grinning:

Yesterday I installed Nextcloud on my Ubuntu Server 20.04, the process run smoothly and I have a working instance of this service.

For a project, I have to implement the following feature: delete an externally shared file AFTER it has been downloaded.

Browsing nextcloud docs i found out about Workflows, and I installed the app called Workflow external scripts (vers. 1.8) since it seems more flexible. Github with readme here: GitHub - nextcloud/workflow_script: Rule based processing of files through specified external scripts · GitHub

So I tried to create a flow that does something like:
When File is accessed AND file system tag IS sometag RUN script rm %n

This flow above does apparently nothing, so I tried with something easier to check:
When File is renamed RUN script touch /tmp/test.txt

Still nothing happens…
I tried to check logs in nextcloud/data/nextcloud.log, but keeping it open with tail -f i see no new lines.
Browsing the web for answers or helps i found this thread Using Workflow External script to generate searchable PDF

I also tried to create an helper bash script like that but still no luck.

Can I have some working example of some simple workflow? Would be super cool if someone knows if the deleting file after download can be feasible in this way.

Thanks

Here is a long-time feature request:

Did you check the documentation? There is also github.

https://docs.nextcloud.com/server/latest/developer_manual/digging_deeper/flow.html

Why not use the downloadlimit app for this?

https://apps.nextcloud.com/apps/files_downloadlimit

2 Likes

Hey thanks, it works :grinning:

Well actually it does not delete the file from nextcloud, but I think I still should be ok with this. The most important thing was to have a one time download.

@anon75456558 That feature request has not been implemented, correct? Yes I read that documentation page, but being honest, I still have no clue on how write a working workflow. The Info there seems much different on what I see in the flow panel (at http://my-nextcloud.com/index.php/settings/admin/workflow)

You can try asking for help with your “share then delete” workflow on the community chat. Might be able to find more advice there.

You can also check out the retention app in case it can help you. Here is the documentation

Yes, I’m using the retention app to have a “base” deleting mechanism.
In this way if the shared file is downloaded, it will be automatically removed after x days, while the share link will instantly decay.
Else, if nobody download the file, it still will be deleted after the retention period.

I actualy have the very same need for a security compliance request. This is to have a special incoming/outgoing system that won’t keep any file more than the required time to exchange them since those are confidential.

Still struggling with download, i don’t see how to trigger in workflow an action once a file is fully downloaded.
I use downloadlimit so the share link disapears, but i would like the file itself to be deleted and didn’t find yet a way to do it.
At least it it could be tagged as uploaded and then use retention to remove it. But i don’t see how to tag it on download.
Can we even be sure that download actualy did complete on the server side ? In facts even if is not possible, having a delay between download notification by external link and removal will be enough to answer to compliance request.

Yes, you can combine a retention period set using the Retention app with a file download limit. Starting with NC 30, the latter can be set directly in the share settings, meaning the ‘File download limit’ app is no longer needed.

For example, you could set a one-week retention period in the Retention app and a download limit of 1 in the share settings, meaning the file would be deleted after a week, regardless of whether it was downloaded, and it could only be downloaded once during that period.

Alternatively, you may get away with simply letting the share expire after a given time instead of automatically deleting the file. Whether or not this is an option, of course, depends on your exact compliance policies. However, in most cases, it is probably more important that files cannot be downloaded multiple times and/or are not publicly available indefinitely than that they are deleted from Nextcloud.

Thanks for your extensive reply.

Unfortunately compliance is really about deleting file from filesystem, and to do it as soon as remote party get it. This has to be seen as a transfer, once it is transferred it should not remains on server.

In this case, it might be easiest to use a dedicated app. After all, if the files need to be deleted after transfer, there isn’t much advantage in using Nextcloud for that. A simpler, dedicated tool designed specifically for this purpose might be a better choice.

I can’t provide a recommendation, but I did a quick search and found the following app that might be worth a look: https://github.com/Forcem/Gokapi.

I’m pretty sure there are many more like it out there if you search online for ‘self-hostable WeTransfer alternative’ or a similar term.

1 Like

Thanks, I will study your solution, this is valuable.

1 Like

i currently went to an alternative called lufi on a yunohost system YunoHost app store | Lufi .

1 Like

I am back on this subject since files can be huge and nextcloud seems more appropriate than lufi for this since lufi does encrypt and decrypt in browser memory.

I fought with run scripts and finally did disable server side encryption with a decrypt-all. It starts to work.

scripts are run through cron jobs so this is delayed, but it definitely seems doable.

i was hoping server side encryption just prevent file handling, not fully prevent event triggering, but …

this is clearly written in Limitations : This app does not work with either encryption method.

UPDATE ( had to, since can’t add 3 replies )

This does not work : workflow_script ‘Consult’ is a postTouch event, while we would like a postRead, which does not exist, or at least a read that is issued at first open file on download.
There does not seems to exist solutions with download triggers yet.

If a file is deleted after upload and a app or desktop synchronisation is setup, then file removal will trigger a new synchronisation actualy removing the file that just has been downloaded.

This scenario looks really outside the scope of what nextcloud offers even with advanced tools.

Please change my mind :wink: