How to create a folder by using API?

Hi.

I have created a little php application which upload a file by using curl to make a webdav call using PUT method. That's working great.
However, I can't manage to use API to create a folder (the idea is to create a folder from php and then upload the file on this new folder).
I have read that I should use OCP instead of OCS or webdav. Also I think I have found the documentation of the function that I have to all: https://doc.owncloud.org/api/classes/OCP.Files.Folder.html#method_newFolder but I haven't found any example on how can I make this call from php.

Could anyone show me an example?

Thank you.

You just need to do a WebDAV call doing a MKCOL, similar how you do the PUT.

Thank you for your answer. I tried but it doesn't seem to work.

I have done this by linux command-line:

curl -X MKCOL "https://myserver/remote.php/webdav/existing_folder/new_folder" -k -u my_user:mypassword

After this call I'm getting this answer:


301 Moved Permanently

Moved Permanently


The document has moved here.




Apache/2.4.10 (Debian) Server at myserver Port 80

But when I login on owncloud with my credentials (myuser / mypassword, according to the example) I can't see the folder.

What I'm doing wrong?

This is really strange, but moving the -X MKCOL option to the end seems to make it work.

So, it's working now. Thank you!!

I am trying to create a folder using owncloud API in java. I get "pkix path building failed sun.security.provider.certpath.suncertpathbuilderexception" because I guess org.apache.commons httpClient cannot trust this server. I tried to solve this by registering self signed certificate to CloseableHttpClient. But I guess CloseableHttpClient does not support jackrabbit MKCOL. Any suggestions on how I can solve this?

Hi,

the url https://doc.owncloud.org/api/classes/OCP.Files.Folder.html#method_newFolder is down, could you please help me?, i need create a folder but i don´t know how.

thanks in advance

Hey,

i’m not sure if the documentation would help you. :confused:

If i’m understanding the following post correctly you should use WebDAV methods instead:

From what i have read in the past the API provided by ownCloud for file operations like uploading/creating/deleting files and folders is WebDAV.

Hi Gabriela,

Not sure what you’re trying to achieve.
Perhaps this can help you?
https://doc.owncloud.com/server/user_manual/files/access_webdav.html#accessing-files-using-curl
Cheers,
Erik

1 Like
  1. curl -X MKCOL <folder_URL> for create a folder.
  2. curl -X PUT <folder_URL>/<file_name> --data-binary @<file_location_in_pc> for upload a file.
1 Like

you can do it using commands.. .

1 Like