Creating new folder using https request from esp8266

Hi everyone… I am able to successfully connect to owncloud from my esp device making http/https request using webdav and also able to download and upload files. But the problem is i am unable to create new folder directly from the esp. when i give new folder path in url it returns the answer which is logical that path does not exist. But i was hoping as i am able to create new file name similar way i could also create new folder. Any help will be appreciated i can share the code upon request. i am using arduino ide and c language.

What exact url are you calling? What are the response headers? Are you using a WebDAV library? …

I don’t think anybody here can help you without it.

1 Like

hi i am calling webdav library url
e.g http://ip/remote.php/webdav/folder

below is my code for uploading a file in my cloud…

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <FS.h>
#include <ArduinoJson.h>

#define FILE “/testfile8.json” //file which i want to create
const char* ssid = “ssid”; // network ssid
const char* password = “pass”; // network passphrase
const char* apiUrl = “http://ip/remote.php/webdav/testproject” FILE;
/testproject folder already exists but when i give new path e.g testproject/testfolder
which does not exist but i was hoping
it will be automatically created as http creates new file too
/

const char* username = “username”; // username
const char* token = “password”; // token or password

#define DBG Serial

void setup(void){

DBG.begin(115200);
DBG.println(“starting…”);
WiFi.begin( ssid,password );
uint8_t max = 16;
while (!WiFi.isConnected() && max–) {
DBG.println(".");
delay(250);
Serial.println(“HTTP server started”);
bool success = SPIFFS.begin();

if (!success) {
Serial.println(“Error mounting the file system”);
return;
}

File file = SPIFFS.open("/testfile5.json", “w”);

if (!file) {
Serial.println(“Error opening file for writing”);
return;
}

int bytesWritten = file.print(“i am 2”);

if (bytesWritten == 0) {
Serial.println(“File write failed”);
return;
}

file.close();

}
}

void loop(void){
static bool cloud_send = false;
if (!cloud_send) {
cloud_send = true;

auto f = SPIFFS.open("/testfile5.json", "r");
const auto f_size = f.size();

Serial.println(f_size);

HTTPClient http;

http.addHeader("Content-Type", "application/json");
http.addHeader("Content-Length", String(f_size, DEC));

http.setAuthorization(username,token);
http.begin(apiUrl);

int http_code;
const auto A = millis();
http_code = http.sendRequest("PUT", &f, f_size);
DBG.printf("\n time-keep: %lus", (millis() - A) / 1000);
http.writeToStream(&DBG);
http.end();
f.close();

}

}

@danny93 Some hints from my side:

  • You can only create folders one level deeper. Eg with an existing folder testproject/, you have to create testproject/foo/ first, then testproject/foo/bar/ and so on. Folder testproject/foo/bar/ cannot be created directly, the direct parent must exist.

  • For creating folders (they are named collections in WebDAV), you have to use the MKCOL request.

Good luck!

2 Likes

hi alferdb thank you for your reply…
i tried with one level deeper but no success … this MKCOL request where in my code can i use this can you please help me out in this regard. where should i put MKCOL in my code

@danny93 But I still have no clue what you try to achieve.
And the code you supplied looks somewhat messy. Its very hard to understand.

2 Likes

What is messy about the code? if you do not understand it then no need to answer… Do you even know what is esp and can you even code in C?? if yes you should be able to understand this code. its very simple . a simple http server to upload file to cloud.

i suggest you work on your c and then if you know the answer we can talk.

Cool down, and sorry for disturbing you.

2 Likes

Thank you…But this function helps to check locally not remotely…You cann create directory in cloud using this function… i have found the solution and its very simple… Thank you though