-1

I am trying to upload a large video to an API. The API made it mandatory that the video must be split into multiple files and uploaded via different URLs that were given to me in a previous initializeUploadRequest.

Now imagine I have a file mymove.mp4 and I am to split the file within this byte range : firstByte= 0 and lastByte= 4194303.

Matt Oestreich
  • 8,219
  • 3
  • 16
  • 41
ololo
  • 1,326
  • 2
  • 14
  • 47

1 Answers1

3

By "split the file", I assume your objective is to send an upload of each byte range portion of the file.

An efficient way to do that is to stream the file to the upload endpoint. You can create a readStream that will stream just a byte range using the start and end options for fs.createReadStream(filename, options).

const readStream = fs.createReadStream(filename, {
  start: firstByte,
  end: lastByte
});

Then, you would presumably use something like .pipe() to integrate this stream with your upload request. You don't show your upload code for us to offer an example of how you would integrate this into that.

jfriend00
  • 683,504
  • 96
  • 985
  • 979