ตัวอย่างการใช้งาน Phaya API ในภาษาต่างๆ
// อัพโหลดไฟล์วิดีโอ
const uploadVideo = async (file) => {
const formData = new FormData();
formData.append('file', file);
const response = await fetch('https://api.phaya.io/api/v1/media/upload', {
method: 'POST',
headers: {
'Authorization': 'Bearer phaya_live_xxxxxxxxxxxx'
},
body: formData
});
if (!response.ok) {
throw new Error(`Upload failed: ${response.statusText}`);
}
const data = await response.json();
console.log('Uploaded:', data);
return data;
};
// ใช้งาน
const fileInput = document.getElementById('videoFile');
uploadVideo(fileInput.files[0])
.then(result => console.log('Success:', result))
.catch(error => console.error('Error:', error));