1

I am trying to download a file with multiple parts on the server.

1 file => 25 chunks

I am sending a request to the server via Axios and getting a response like this one.

enter image description here

My goal is to send a request for 25 chunks and combine all data into a single file.

My code:- (Getting invalid file)

async function getChunks() {
  let i = 0
  for (const url of urls) {
    try {
      const response = await axios.get(url)
      if (i !== 0) {
        const data = fs.readFileSync(`test.txt`, 'utf8')
        console.log(typeof response.data)
        fs.writeFileSync('test.txt', data + response.data, 'binary')
      } else {
        fs.writeFileSync('test.txt', response.data, 'binary')
      }
      i++
    } catch (error) {
      console.log(`unable to get chunk ${url}`)
    }
  }
}
sanket kheni
  • 1,482
  • 2
  • 12
  • 29
  • look into it https://stackoverflow.com/questions/56826079/how-to-concat-chunks-of-incoming-binary-into-video-webm-file-node-js – Mohit Sharma Jun 19 '22 at 12:30

0 Answers0