Uploading a file to File Drop using http post method

Dear Nextcloud team and devs,

I am trying to make my ruby application upload a zip file to a file drop folder in my nextcloud, but I only get 405 answers from nextcloud. Unfortunately, I was unable to find any documentation on how to do this or how such a post request is supposed to look like.
Can someone please hint me to what exact url and headers to use?

The only thing I found on that topic is this little curl script, but it did not help making it work (and it looks a bit outdated).

Thanks,
Amo

There is a client library in python, https://github.com/owncloud/pyocclient, perhaps this helps you to get some inspiration. I have only tried with a client login, never as a file drop.

And the API documentation:
https://docs.nextcloud.com/server/16/developer_manual/client_apis/index.html

Thank you a lot for pointing me to the right direction. It seems like I should be using a PUT request instead of a POST request.
Now I can get some results when testing with curl, though the upload is not successful yet.

The API documentation states that all requests need to provide authentication information, either as a Basic Auth header or by passing a set of valid session cookies. But this somehow defeats the purpose of having a public upload (file drop) page which does not need an account.

If I give curl test:test for user:password, just so to make it send an auth header, I get the error “No public access to this resource., Username or password was incorrect”.

Hi buddy, do trying looping from the custom login url that should solve it.

Regards,
Teju Bessey https://dltutuapp.com/tutuapp-download/ https://showbox.run/ https://kodi.software/

Thank you for the idea!

Unfortunately, I don’t really understand what you mean by looping from the login url… and which custom login url?

Could you please help me out with a few explanations or a quick example?

Ok so after a long time of searching and trying I figured out a way to do this. Here is my solution in case somebody happens to be trying the same thing:

In Ruby we can upload easily using the PUT (not POST) with the mechanize gem:

webdav_path = "public.php/webdav/files/user/folder/#{filename}"
full_url = "https://example.com/#{webdav_path}"
agent = Mechanize.new
agent.add_auth(full_url, 'folder', '')
agent.put(full_url, File.open(filename, "r").read, {'X-Requested-With' => 'XMLHttpRequest', 'Content-Type' => 'application/zip'})

Seemed important to set the X-Requested-With header, to use the webdav path and to set basic auth to the folder as username and empty password.

Another thing I found very helpful to figure this out is this cURL script.