The nextcloud manual describes a possibility to create anonymous upload space for users.
If one creates such an upload space, a URL is created and can be shared, allowing multiple users without nexcloud accounts to upload files.
However, these files need to be dragged and dropped into a browser window. In contrast, I want to directly upload them in a python program. I cannot really use a nextcloud package for this such as described here, since I do not have (and do not want to create) user accounts for every uploader.
Any ideas how to proceed? I could use a package such as selenium to imitate user actions in the browser, but that seems somewhat clumsy.
[EDIT:]
And have used a curl command as described here for owncloud, hoping that this would work similarily for nextcloud, and I translated the curl command using curlconverter, but got an error 405.
[EDIT 2:] I got a little bit further with the following modified code (modified URL), which returns status 200. But I still don't see an uploaded file.
headers = {'X-Requested-With': 'XMLHttpRequest',}
with open('test.txt', 'rb') as f:
data = f.read()
response = requests.put(
'https://xxx.xxx.com/remote.php/s/test.txt',
headers=headers,
data=data,
verify=False,
auth=('94daw3R3sfwrNaeK', ''),
)
[EDIT 3:] It seems that the problem is related to the URL in use. I am rechecking with direct use of CURL.
As expected, a change in URL was necessary. This piece of code did the trick:
headers = {'X-Requested-With': 'XMLHttpRequest',}
with open('test.txt', 'rb') as f:
data = f.read()
response = requests.put(
'https://xxx.xxx.com/public.php/webdav/test.txt',
headers=headers,
data=data,
verify=False,
auth=('94daw3R3sfwrNaeK', ''),
)