I was writing a code to upload a video to the Stream API in BunnyCDN, but I get a CORS error
My Code:
const apiKey = 'API_KEY';
const libraryId = 'LIBRARY_ID';
const createVideoUrl = `https://video.bunnycdn.com/library/${libraryId}/videos`;
const fileInput = document.getElementById('file-input');
const title = document.getElementById('title');
const collectionId = document.getElementById('collection-id');
const createButton = document.getElementById('create-button');
let videoId;
createButton.addEventListener('click', async () => {
console.log('Creating video...');
const response = await fetch(createVideoUrl, {
method: 'POST',
headers: {
accept: 'application/json',
'Content-Type': 'application/*+json',
AccessKey: apiKey
},
body: JSON.stringify({
title: title.value,
collectionId: collectionId.value,
}),
mode: 'cors' // I tried no-cors and without that value too. But nothing changes
});
const data = await response.json();
videoId = data.guid;
document.write('Video created with ID:', videoId);
});
Normally, this request should be sent and the id of the video should be returned.
Documentation: Create Video