We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
alaaNabawy
7 years agoExplorer | Level 3
Can't stream my videos beacause of cors
Hello, I tried to stream my videos from dropbox in my site with shared with javascript to create blob source link but there is an issue with cors,
the code
<video id="my-video" class="video-js" controls preload="metadata" width="640" height="264"
data-setup="{}">
</video>
<script type="text/javascript">
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
var byteCharacters = atob(reader.result.slice(reader.result.indexOf(',') + 1));
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var blob = new Blob([byteArray], {type: 'video/ogg'});
var url = URL.createObjectURL(blob);
document.getElementById('my-video').src=url;
}
reader.readAsDataURL(xhr.response);
};
xhr.open('GET', 'https://www.dropbox.com/s/0tztdjct8uuwgl5/flowers.mp4?dl=1');
xhr.send();
</script>What can i do?
9 Replies
- Greg-DB7 years ago
Dropbox Community Moderator
The 'www.dropbox.com site' doesn't allow CORS like this.
You can technically make this work using 'dl.dropboxusercontent.com' (e.g., "https://dl.dropboxusercontent.com/s/0tztdjct8uuwgl5/flowers.mp4"), but please note that isn't officially supported.
- alaaNabawy7 years agoExplorer | Level 3
How can i do that with dropbox api?
- Greg-DB7 years ago
Dropbox Community Moderator
You can list existing shared links or create new shared links using the Dropbox API. The Dropbox API only returns the supported version of the links. If you want to use the unsupported versions, you'd have to perform the string modification in your code.
- alaaNabawy7 years agoExplorer | Level 3
Is there any expected problems if i use unsupported version?
- Greg-DB7 years ago
Dropbox Community Moderator
The unsupported form of shared links is subject to change/break without warning.
- alaaNabawy7 years agoExplorer | Level 3
I can't understand your last comment?
- Greg-DB7 years ago
Dropbox Community Moderator
The "dl.dropboxusercontent.com" shared links currently happen to work for this, but I can't promise they will continue to. It may break without warning.
- alaaNabawy7 years agoExplorer | Level 3
Please review that
https://stackoverflow.com/questions/54046326/curl-code-request-for-my-code-in-php-to-make-a-request
- Greg-DB7 years ago
Dropbox Community Moderator
It looks like you're requesting sample code for calling /2/sharing/list_shared_links from PHP. I don't have a sample for that endpoint in PHP unfortunately. Please write the code you need, using the documentation and curl example as a reference, and let us know if something isn't working as expected.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!