Last active
January 25, 2023 13:48
-
-
Save mustafaboleken/214d166ee545bbd0f3da1b544e9fea28 to your computer and use it in GitHub Desktop.
Ant Media Server upload vod with plain js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>File Uploader</title> | |
</head> | |
<body> | |
<h2>File Upload Service</h2> | |
<input type="file" id="files"> | |
<button id="upload">Upload</button> | |
<small id="status"></small> | |
<script> | |
const files = document.getElementById('files'); | |
const upload = document.getElementById('upload'); | |
const status = document.getElementById('status'); | |
upload.addEventListener('click', () => { | |
status.innerHTML = 'uploading...'; | |
let file = files.files[0]; | |
let fileName = files.files[0].name; | |
let fileSize = files.files[0].size; | |
let formData = new FormData(); | |
formData.append('file', file); | |
formData.append('file_info', fileName); | |
fetch('https://ANT_MEDIA_SERVER_DOMAIN:5443/LiveApp/rest/v2/vods/create?name=' + fileName, { | |
method : 'POST', | |
body : formData | |
}).then(res => { | |
if (res.status === 200) { | |
status.innerHTML = `file ${fileName} uploaded!!!`; | |
} else { | |
status.innerHTML = `file ${fileName} upload failed!!!`; | |
} | |
}) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment