Skip to content

Instantly share code, notes, and snippets.

@ndkv
Last active March 18, 2022 09:35
Show Gist options
  • Save ndkv/d31004555f1773ca2d7778fb0b9beb74 to your computer and use it in GitHub Desktop.
Save ndkv/d31004555f1773ca2d7778fb0b9beb74 to your computer and use it in GitHub Desktop.
Mux API test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://unpkg.com/@mux/upchunk@2"></script>
</head>
<body>
<h1>mux</h1>
<p>{{ upload_url }}</p>
<input id="picker" type="file" />
<script>
const picker = document.getElementById('picker');
picker.onchange = () => {
const upload = UpChunk.createUpload({
endpoint: '{{ upload_url }}',
file: picker.files[0],
chunkSize: 256
});
// subscribe to events
upload.on('error', err => {
console.error('💥 🙀', err.detail);
});
upload.on('progress', progress => {
console.log(`So far we've uploaded ${progress.detail}% of this file.`);
});
upload.on('success', () => {
console.log("Wrap it up, we're done here. 👋");
});
};
</script>
</body>
</html>
import mux_python as mux
from flask import Blueprint, render_template
bp = Blueprint('video_view', __name__)
@bp.route('/video/mux')
def upload_url_mux():
configuration = mux.Configuration()
configuration.username = '1234'
configuration.password ='5678'
api = mux.DirectUploadsApi(mux.ApiClient(configuration))
asset_request = mux.CreateAssetRequest(playback_policy=[mux.PlaybackPolicy.PUBLIC])
upload_request = mux.CreateUploadRequest(
timeout=3600,
new_asset_settings=asset_request,
cors_origin="*")
upload_url = api.create_direct_upload(upload_request).data.url
return render_template(
'private/studio/video_mux.html',
upload_url=upload_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment