cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't stream my videos beacause of cors

Can't stream my videos beacause of cors

alaaNabawy
Explorer | Level 3

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 9

Greg-DB
Dropbox Staff

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.

 

alaaNabawy
Explorer | Level 3

How can i do that with dropbox api?

Greg-DB
Dropbox Staff

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.

alaaNabawy
Explorer | Level 3

Is there any expected problems if i use unsupported version?

Greg-DB
Dropbox Staff

The unsupported form of shared links is subject to change/break without warning.

alaaNabawy
Explorer | Level 3

I can't understand your last comment?

Greg-DB
Dropbox Staff

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.

alaaNabawy
Explorer | Level 3

Greg-DB
Dropbox Staff

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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    alaaNabawy Explorer | Level 3
What do Dropbox user levels mean?