How to create automatically more than 1 public shared link?

Hi everyone,

I am working in a Project and I would like to have a public link for each file I have in my Nextcloud, and I would like to know if there is an automatic way to do it, or if it is posible changing some code.

I tried to share the folders, but I would need one public link for each document inside this folder, and this option is just to create one single link to share the content.
I was looking for information in forums, but i did not find anything…


There is a python client library for Nextcloud:

You can just list all files in a folder and then create a share link for each of them. It should work with this version, however I’d like to extend the feature list a bit that you can also use it for tagging, comments and more stuff. But what you want should already be possible.

Let us know if you managed to do it like this, it should be just a few lines of code.

1 Like

That was perfect! Thank you! :smiley:

Finally, I added some lines of code, and now the script creates a public link for each file I have.

import glob
import os
import owncloud

oc = owncloud.Client('http://domain.tld/owncloud')

oc.login('user', 'pwd')


for file in glob.glob("*"):
  link_info = oc.share_file_with_link('path/' + file)
  print "Here is your link: " + link_info.get_link()

Now I am going to try to rename all the publics links, if you guys know any way to do it automatically, i will appreciate it.

Thank you!:wink:


I’m looking to upload a file and create a public sharing link.
I can communicate with nextcloud and send a file to it. But I can’t create a share link.
When I use the following command: link_info = oc.share_file_with_link(‘myFolder/myFile.txt’) I get the error below :

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\owncloud\", line 913, in share_file_with_link
    raise HTTPResponseError(res)
owncloud.owncloud.HTTPResponseError: HTTP error: 401

Do you know how to solve the problem?
Did I forget an option, an authorisation?

Thanks for your help