Thanks for the question. The issue that arises with copying large files is that if there is any transport error, the upload will fail. The reason we recommend smaller byte range uploads is to minimise the time spent with failed uploads. You could try to upload the large video using the source attribute, and it may work (assuming no transport issues).
However, if the full upload fails, you’ll need to copy the video, break it into chunks, and then upload the segments, as outlined in the documentation & the tutorial (docs.spi.video)
Right, so is it possible to split a file using JavaScript within a website? Sounds like splitting the file anywhere other than the users’ local machine is not possible because you’d just encounter the same issue of sending a large file somewhere else.
If you have file access on the server, file.slice might do what you are looking for:
In regards to downloading/slicing/uploading: HTTP has issues UPLOADING large files, but not DOWNLOADING them. So the process of copying to your machine (or server) should be fine. Then you can split & upload the segments.
I am referring to uploading videos on a website within a browser.
async ({ videoId }) => {
const chunkSize = 125000000; // 125 MB
for (let from = 0; from < videoFile.size; from += chunkSize + 1) {
const to = Math.min(videoFile.size - 1, from + chunkSize);
const chunk = videoFile.slice(from, to);
const formData = new FormData();
formData.append('data', chunk);
await fetch(`https://sandbox.api.video/videos/${videoId}/source`, {
method: 'POST',
headers: {
Authorization: `Bearer ${videoAPIAccessToken.current}`,
'Content-Range': `bytes ${from}-${to}/${videoFile.size}`,
},
body: formData,
});
}
})
This is what I have right now, it uploads files in chunks, there is no server error, and a video container is created. However, if the video is sent in multiple chunks (i.e. file size is greater than chunkSize), the uploaded video on the dashboard will just show the 5 second “This video is being processed…” placeholder. If the uploaded video file size is less than chunkSize, the video is uploaded properly and you can watch it online. Can you spot the issue in my code?
I guess could you just share the code snippet used to upload video files on “https://go.api.video/”? That works well and uploads videos a lot faster than my code for some reason.
We have SUCCESSFULLY implemented API.video into our commercial product and have uploaded files as large as 12 gig using chunking as described. It DOES work and works well