Balu
Balu

Reputation: 564

How can i delete directory in Azure datalake Store using httpclient API

I can delete a file in Azure using the httpclient API , But how can I delete a directory in Azure's datalake Store using the httpclient API?

File Delete Code

     private const string DeleteUrl = "https://{0}.azuredatalakestore.net/webhdfs/v1/{1}?op=DELETE";

public string DeleteFile(string path)
        {
            var deleteUrl = string.Format(DeleteUrl, _datalakeAccountName, path);
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesstoken.access_token);
                var res = client.DeleteAsync(deleteUrl).Result;
                var data = res.Content.ReadAsStringAsync().Result;
                return data;
            }
        }

Upvotes: 0

Views: 625

Answers (1)

Tom Sun
Tom Sun

Reputation: 24569

But how i How can i delete directory in Azure datalake Store using httpclient API

Please have try a try use the following URL to delete the directory

 private const string DeleteUrl = "https://{0}.azuredatalakestore.net/webhdfs/v1/{1}?api-version=2017-08-01&op=DELETE&recursive=true";

If recursive=true then will delete all of the files in the directory include the directory itself.

If recursive=false and there are files in the directory will get 403 forbidden error.

enter image description here

Upvotes: 1

Related Questions