With your own Nextcloud server, you can access your stored data from anywhere. It can also be used to share data with others. Folders can be shared with the upload only file drop option. With this share, data can only be uploaded to the server via a web interface. This solution is perfect for project data, surveys or similar application examples.
Is there a possibility to access these shars with a script?
The answer is YES and it is very simple.
I found this Blog from Georgi Nikolov. He create a script for Linux that can upload data to Nextcloud File-Drop shares using CURL. But I don’t work with Linux. Unfortunately, I have not found an Windows alternative either. That’s why I built one myself.
The Solution
create File Drop
Create a shared link for a Nextcloud folder. Select the „File Drop (upload only)“ option, or „Allow upload and editing“ when creating the shared link.

… and copy the shared link url

My link looks like this:https://mynextcloudserver.at/xxx/s/Y4cQ2DLJeCAXRLD
We need to separate this URL into two parts. The first part is the NextcloudUrl, the second is the ShareToken.$NextcloudUrl = "https://mynextcloudserver.at/xxx/"
$sharetoken = 'Y4cQ2DLJeCAXRLD'
Now we just need to specify the file for upload.$Item = "C:\Temp\test.zip"
edit and run the script
$Item = "C:\Temp\test.zip"
$NextcloudUrl = "https://mynextcloudserver.at/xxx/"
$sharetoken = 'Y4cQ2DLJeCAXRLD'
$Item = Get-Item $Item
$Headers = @{
"Authorization"=$("Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($("$($sharetoken):"))))");
"X-Requested-With"="XMLHttpRequest";
}
$webdav = "$($NextcloudUrl)/public.php/webdav/$($Item.Name)"
Invoke-RestMethod -Uri $webdav -InFile $Item.Fullname -Headers $Headers -Method Put
Output

File in Nextcloud 🙂

Now we can easily upload files directly to our File Drop Nextcloud link in 2 easy steps. Enjoy!
P.S: Powershell rocks!
Update 16.09.2021
Unfortunately, this solution no longer works. Something might have changed here.
Hi, nice Articel, but when i try the script i only get
Invoke-RestMethod :
404 Not Found
404 Not Found
nginx
kind regards
Tobias
Hi Tobias,
which Nextcloud version are you using?
404 means that the page was not found.
Please check if the shared link URL or webdav URL works in your browser. At least you should be able to open it.
Thats indeed a nice article unfortunately it doesn’t seem to work for me 🙁
I get a Invoke-RestMethod : The remote server returned an error: (405) Method Not Allowed.
Found some info regarding web application firewall might cause this but even without a firewall in between it doesn’t seem to work.