3

I'm trying to store files into HDFS from an application written in C++. I know you can use curl in command line/terminal:

First send a PUT request,

1) curl -i -X PUT http://<name_node>:50070/webhdfs/v1/<path>?op=CREATE

and then write data to the data node with the redirected address,

2) curl -i -X PUT -T <local path> "http://<data_node>:50075/webhdfs/v1/<path>?op=CREATE...

I want to know how to store data to HDFS directly using libcurl in c++.

Note: I'm able to send GET requests and it all works perfectly:

string url = "http://localhost:50070/webhdfs/v1/mydata/restAPI.txt?op=GETCONTENTSUMMARY"    
if (curl)
        {
            curl_easy_setopt(curl, CURLOPT_URL, url1.c_str());
            result = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }
mintuchiha
  • 31
  • 1
  • 3

1 Answers1

3

It is better to use curl such that it automatically redirect after step 1. The following command worked in my case :

curl -L -i -X PUT -T local_file "http://:50075/webhdfs/v1/?op=CREATE...

Malathi
  • 2,119
  • 15
  • 40