Using the ownCloud Python package I have written a small script (see below) to upload files via a bash alias. While the desktop clients are great for quickly sharing files I often find using this script more efficient and it also works in headless environments.
With Nextcloud 15+ the ability to “Hide Download Link” was added via the files interface. I’m wondering if this feature is accessible from the Python package. In the same vein, I’m wondering if there’s a function to set expiration.
I’m fairly new to writing and reading Python and also know that the class was originally for ownCloud and hasn’t been updated in some time. If there’s another Python package for Nextcloud or WebDAV that I should be using please point me in that direction.
Ideally, the goal is to be able to run it like this:
python 3 nextcloud.py Some/File/image.jpg true 86400 which would upload the file, hide the download link, then set the expiration to one day.
Looking forward to the communities thoughts.
import sys from pathlib import Path domain = 'https://example.com/' user = 'python' password = '12345abcxyz' remoteDirectory = 'public-uploads' fullFilePath = str( ' '.join( sys.argv[1:] ) ) try: pathParts = fullFilePath.rsplit( '/', 1 ) localName = pathParts except IndexError: localName = fullFilePath fileName = remoteDirectory + '/' + localName.replace(" ", "_") if not Path( fullFilePath ).exists() : print ( "File not found, check the following: \n1) Did you include the absolute path to file? \n2) Did you use quotes around the filename?" ) sys.exit (1) oc = owncloud.Client( domain ) oc.login( user, password ) oc.put_file( fileName, fullFilePath ) linkData = oc.share_file_with_link( fileName ) print ('Public link: %s' % ( linkData.get_link() ) )