Batch mode link sharing

I wonder if there is a way to share files via link in batch mode.

So the background is I have a system which provides files which have to be shared.
The transport of the files to nextcloud could look like using the desktop client of just putting the files in the filesystem of the nextcloud server via SFTP.

And I think the missing puzzle tile would be some kind of binary to call from the cloud server cli which activates the share with a defined end time and returns the link.

So maybe someone has an idea about that.

Ok, nice.
I found a way putting files directly in the cloud data path and inform nextcloud about that via occ files:scan command.
But I’m not able to create a link for sharing using occ command.
So maybe there is another way to do this.

@tazinblack : did you find a way to automatically create the link? I’m trying to do exactly the same thing (automatic link creation without user interaction).

After talking about it on IRC, the solution is to use the share API .

An example given by coke here:
curl -u user:secret -X POST https://nextcloud/ocs/v1.php/apps/files_sharing/api/v1/shares -d path="Photos" -d shareType=3 -d permissions=1 -d expireDate="2017-04-01"

1 Like

Sorry for the delay, I haven’t noticed that there were any replies.
Maybe my spamfilter was running wild?

For me it would be interesting to create shareType = public link which looks it is defined.
According to the api documentation you will get a XML back containing the share id.
No idea how this will look like, but I think it’s worth a try.

Or did you already manage to do so?

You could try to use this:

When I try do share via share API as mentioned above with curl I always get a

{"message":"CSRF check failed"}

The command I used was

curl -u "myuser:mypassword" -X POST https://nextcloud/ocs/v1.php/apps/files_sharing/api/v1/shares -d path="globalshare/0002/pic.jpg" -d shareType=3 -d permissions=1 -d expireDate="2017-07-20"

Any Ideas?

Is there also a client library for PHP which can be used?

Nice, looks like I found it

-H "OCS-APIRequest: true" was missing.

curl -u "myuser:mypassword" -H "OCS-APIRequest: true" -X POST https://nextcloud/ocs/v1.php/apps/files_sharing/api/v1/shares -d path="globalshare/0002/pic.jpg" -d shareType=3 -d permissions=1 -d expireDate="2017-07-20"

See here https://github.com/nextcloud/server/issues/2753

2 Likes