title: Read file from Azure Databricks DBFS REST 2.0 API
body: <p>I am working on an application to read and write files using Azure Databricks DBFS API 2.0. Reference Documentation for this API:
  <a href="https://docs.azuredatabricks.net/api/latest/dbfs.html#read" rel="nofollow noreferrer">https://docs.azuredatabricks.net/api/latest/dbfs.html#read</a></p>
  
  <p>I am able to upload file (lets say 1.4MB file) by converting it into base64 then divided into 1MB chunks of data.</p>
  
  <p>As the read length is limited to 1MB, I am iterating a loop to read data from offset <code>0</code> to <code>1000000</code> and <code>1000001</code> to <code>end of the file</code>. Now the first iteration of data, <code>0</code> - <code>1000000</code>, is valid and I can confirm from the original file which i used for upload.</p>
  
  <p>But the second and later data iterations, the base64 data is completely different and not present in the original base64 file.</p>
  
  <p>Following is my test code:
  <code>Second iteration</code> - 0.4MB</p>
  
  <pre><code>const axios = require('axios')
  const fs = require('fs')
  
  axios({
    method: 'get',
    url: 'https://********.azuredatabricks.net/api/2.0/dbfs/read',
    data: {
      path: '/Test/backlit-beach-clouds-1684881.jpg',
      offset: 0,
      length: 1000000
    },
    headers: {
      'Authorization': `Bearer ****`
    }
  }).then(({data}) =&gt; {
    if (data) {
      console.log('Success', data.bytes_read)
      fs.writeFile('./one.txt', data.data, function (err) {
        console.log('done', err)
      })
    } else {
      console.log('failed')
    }
  })
  </code></pre>
  
  <p><code>First iteration</code> - 1MB</p>
  
  <pre><code>const axios = require('axios')
  const fs = require('fs')
  
  axios({
    method: 'get',
    url: 'https://********.azuredatabricks.net/api/2.0/dbfs/read',
    data: {
      path: '/Test/backlit-beach-clouds-1684881.jpg',
      offset: 1000001,
      length: 1000000
    },
    headers: {
      'Authorization': `Bearer ****`
    }
  }).then(({data}) =&gt; {
    if (data) {
      console.log('Success', data.bytes_read)
      fs.writeFile('./two.txt', data.data, function (err) {
        console.log('done', err)
      })
    } else {
      console.log('failed')
    }
  })
  </code></pre>
  
  <p>Here, *** are replaced with relevant domain and tokens.</p>
  
  <p>As you can see, the above test code samples will generate <code>one.txt</code> and <code>two.txt</code>. By using <code>cat one.txt two.txt &gt; final.txt</code> I can get <code>final.txt</code> which I will use to decode original file.</p>
  
  <p>As this is just a testing code, I haven't used any loops or better coding format. This is just to understand what went wrong.</p>
  
  <p>I stuck with this for over 1 week now. I am referring other code samples written for python, but no help.</p>
  
  <p>I am not trying to waste anyone's time. But please, someone help me to figure out what went wrong or any other standard procedure that I can follow?</p>