title: How to upload File to Azure Data Lake through Typescript REST CALLS
body: <p>My problem was to upload the file from local directory to Azure Data Lake Store using Typescript only. I then found very useful REST API solution, I tested the REST API to perform all the required operations through postman and they worked fine, I then moved to Typescript to make these calls from typescript. Here is link to that: <a href="https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-rest-api" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-data-operations-rest-api</a></p>
  
  <p>To make REST CALLS through Typescript I'm using <strong>request-promise</strong> package, that I installed using <strong>npm install request-promise</strong> command. The documentation of this package is provided in this link:- <a href="https://github.com/request/request" rel="nofollow noreferrer">https://github.com/request/request</a></p>
  
  <p>But i'm able to perform all operations of the REST API i.e; Service-to-Service authentication, Creating Folder, Listing Folders, Rename File, Read File and so on. But i am not able to perform two operations/REST CALLS i.e; <strong>Upload File and Delete File</strong>, every time I make this call it gives <strong>Run Time Exception and error code 501 saying that this operation has not been implemented</strong> though i have tested these operations through Post Man and they work fine that way. </p>
  
  <p>Is there any Access problem or what? </p>
  
  <p>Here is the code of Typescript: </p>
  
  <pre><code>var fs = require('fs');
  var request = require('request-promise');
  var accessToken; 
  
  
  getAccessToken();
  setTimeout(listFolders, 5000);
  setTimeout(renameFile, 5000);
  setTimeout(uploadData, 5000);
  setTimeout(readData, 5000);
  
  
  function getAccessToken() {
      request(
      {
          method: 'post',
          url: 'https://login.microsoftonline.com/067e9632-ea4c-4ed9-9e6d-
          e294956e284b/oauth2/token',
          form: {
              grant_type: 'client_credentials',
              resource: 'https://management.core.windows.net/',
              client_id: 'dc9a4034-b03f-4974-9760-99541137a31c',
              client_secret: 'mJ1Eba+sz0hXQko7gBN3D5WPDVLySCHXg4Mg5F4Ru4s='
          },
          json: true,
      }, function (error, response, body) {
          //Print the Response
          accessToken = body.access_token;
          console.log(accessToken);
      });
  }
  function uploadData() {
      fs.createReadStream('E:/accessToken.txt')
      .pipe(request({
      method: 'post',
      url:
    'https://bswadls.azuredatalakestore.net/webhdfs/v1/iModelAnalytics/abc.txt?
     op=CREATE',
     json: true,
     headers: {
          "Authorization": "Bearer " + accessToken,
      }
      },
      function (error, response, body) {
      console.log(response.status);
          }
      ));
  
  }
  
  function readData() {
    request(
      {
          method: 'GET',
          url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/iModelAnalyti
          cs/readFile1.txt?op=OPEN'
          headers: {
              "Authorization": "Bearer " + accessToken,
          },
          json: true,
      }, function (error, response, body) {
          //Print the Response
          console.log("\n\nData = "+body);
          //console.log(response);
      }
  );
  }
  
  function listFolders() {
      request(
      {
          method: 'GET',
          url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/
          iModelAnalytics?op=LISTSTATUS',
          headers: {
              "Authorization": "Bearer " + accessToken,
          },
          json: true,
      }, function (error, response, body) {
          //Print the Response
          console.log("************List Folders*****************\n ");
          console.log(body);
      }
  );
  }
  
  function deleteFile() {
      request(
      {
          method: 'PUT',
          url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/
          iModelAnalytics/readFile.txt?op=DELETE',
          headers: {
              "Authorization": "Bearer " + accessToken,
          },
          json: true,
      }, function (error, response, body) {
          //Print the Response
          console.log("***************Delete File*****************\n ");
          console.log(body);
          console.log('Response= \n');
          console.log(response);
      }
  );
  }
  
  function renameFile() {
      request(
      {
          method: 'PUT',
          url: 'https://bswadls.azuredatalakestore.net/webhdfs/v1/
          iModelAnalytics/readFile1.txt?
          op=RENAME&amp;destination=/iModelAnalytics/readFile2.txt',
          headers: {
              "Authorization": "Bearer " + accessToken,
          },
          json: true,
      }, function (error, response, body) {
          //Print the Response
          console.log("*************************Delete File*****************\n 
     ");
          console.log(body);
          console.log('Response= \n');
          console.log(response);
      }
  );
  } 
  </code></pre>
  
  <p>This is the error that I get:
  <a href="https://i.stack.imgur.com/tDla3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tDla3.png" alt="enter image description here"></a></p>
  
  <p>Please share any thoughts regarding this. </p>
  
  <p>Thanks a lot in advance.</p>