I am uploading videos in bunny stream with JavaScript videos are uploading success fully but videos are empty and corrupted.
please help me it is very important to complete it thanks
here is my code:
const fileInput = document.getElementById('videoFile');
let file = fileInput.files[0];
console.log(file);
video_name = file.name;
let video;
const toBase64 = file => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = error => reject(error);
});
async function Main() {
video = await toBase64(file);
}
video = Main();
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
accept: 'application/json',
AccessKey: 'e3214df7-7dba-4a74-b93649716004-454b-46c3'
},
body: JSON.stringify({ 'title': video_name }),
};
result = fetch('', options)
.then(res => res.json())
.then(res => {
videoId = res.guid;
console.log(videoId);
const options = {
method: 'PUT',
headers: {
AccessKey: 'e3214df7-7dba-4a74-b93649716004-454b-46c3',
'Content-Type': 'application/octet-stream',
},
data: video,
};
fetch(`/${videoId}`, options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
})
.catch(err => console.error(err));
want solution of that its important