cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

How to get the valid url using dropbox api media endpoint.?

Explorer | Level 3

Goal is to play audio file from dropbox. Using dropbox python sdk I can get the folders and files but the `media` doesn't have valid file to play with.

 

    def post(self, request):
        request_body = json.loads(request.body)
        path = request_body['path']
        client = helper.dropbox_client(request.user.profile.dropbox_access_token)
        media_info = client.media(path=path)
        return JsonResponse(media_info, safe=True)

 

The `media_info` have the dict contains `url` but that is not valid means it not playing the content.

How do make that work ?

5 Replies 5
Highlighted

Re: How to get the valid url using dropbox api media endpoint.?

Dropboxer
Dropboxer

[Cross-linking for reference: https://stackoverflow.com/questions/41807719/how-to-get-the-valid-url-using-dropbox-api-media-endpoi... ]

 

Can you elaborate on what the issue you're running in to with the URL is? Are you getting an error? 

Highlighted

Re: How to get the valid url using dropbox api media endpoint.?

Explorer | Level 3

After getting the response from Dropbox. I insert that url into audio player and seems it's not playing. The URL is not valid. If I copy paste that url into address bar it's not playing. My safari audio player simply shows Error.

 

Codes:

 

// HTML

 

<audio id="awesome-player" controls="" autoplay="">
<source id="mp3" src="" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>

 

 

// Javascript

var awesomePlayer = document.getElementById('awesome-player');
awesomePlayer.src=json.url;
awesomePlayer.play();

Highlighted

Re: How to get the valid url using dropbox api media endpoint.?

Dropboxer
Dropboxer
The API is returning a valid URL for me. Can you share a sample URL that's giving you trouble? Thanks in advance!
Highlighted

Re: How to get the valid url using dropbox api media endpoint.?

Explorer | Level 3
Thanks for the reply. This is the url I'm getting in the response.

https://dl.dropboxusercontent.com/1/view/npfkvmyekl783z9/wave.mp3
Highlighted

Re: How to get the valid url using dropbox api media endpoint.?

Dropboxer
Dropboxer

Thanks! That's a valid URL, and it is responding successfully:

 

$ curl -v "https://dl.dropboxusercontent.com/1/view/npfkvmyekl783z9/wave.mp3" > wave.mp3

> GET /1/view/npfkvmyekl783z9/wave.mp3 HTTP/1.1
> Host: dl.dropboxusercontent.com
> User-Agent: curl/7.42.1
> Accept: */*

< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 24 Jan 2017 05:54:26 GMT
< Content-Type: audio/mpeg
< Content-Length: 478
< Connection: keep-alive
< content-disposition: inline; filename="wave.mp3"; filename*=UTF-8''wave.mp3
< set-cookie: uc_session8hTm61TndsDEYzqACTPuaZ66N7IjRoiESu0zqv42e3rOcWV3WuNCQRDzYGUKSPS; Domain=dropboxusercontent.com; httponly; Path=/; secure
< accept-ranges: bytes
< etag: 11n
< x-dropbox-request-id: 1e0a8355c6effc46ece87bdf30885895
< pragma: public
< cache-control: max-age=60
< X-Server-Response-Time: 173
< X-Robots-Tag: noindex, nofollow, noimageindex
<
{ [478 bytes data]

$ cat wave.mp3
bplist00�_WebMainResource�


_WebResourceData_WebResourceMIMEType_ebResourceTextEncodingName^WebResourceURL_WebResourceFrameNameO�<html><body><video controls="" autoplay="" name="media" style="max-width: 100%; max-height: 100%;"><source src="http://www.sample-videos.com/audio/mp3/wave.mp3" type="audio/mpeg"></video></body></html>Zaudio/mpegUUTF-8_/http://www.sample-videos.com/audio/mp3/wave.mp3P
�

The linked file is only 478 bytes though, so it's probably not the data you actually want. Looking at the data itself, it doesn't seem to actually be mp3 data, but rather a webarchive file. You should go back to where you were trying to get the mp3 file and save the actual mp3 file. 

 

 

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?