简体   繁体   中英

Getting mp3 data from google app engine's blobstore via ajax

I'm trying to store audio files in google app engine's blobstore and play them in a browser. The problem I'm running into is that the data I'm getting in the browser is the actual mp3 data. I was expecting to get a url to play the mp3 in the blobstore. So, my question is, what do I need to change to get a url to play the blob instead of the audio data?

Here is my server side handler.

class ServeBlobHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):

    user = users.get_current_user()
    query = db.GqlQuery("SELECT * FROM AudioData Where userId = :1", user.user_id())

    results = query.fetch(limit=300)
    for dStoreEntry in results:

        entityBlobInfo = dStoreEntry.audioBlob

    self.send_blob(entityBlobInfo)

This is the client side.

$.ajax({
    url : '/serve_blob/audio/',
    type : 'GET',
    dataType : 'text',
    success : function(data) {
        alert('GET, audio data : \n '+ data );
    }
});

What Content-type header does your browser get for mp3 request? I'm guessing it's application/octet-stream

See what Blobstore docs say about upload:

If you don't specify a content type, the Blobstore will try to infer it from the 
file extension. If no content type can be determined, the newly created blob is 
assigned content type application/octet-stream

Go to GAE admin pages and check Blob Viewer to see under what content type was assigned to your mp3 files.

The URL of the page that you're currently fetching the data from is the URL of the MP3. You'll need to use a web-based player of some sort to play it.

Get JPlayer - http://www.jplayer.org/

And then your example should work fine. We use it with appengine blobstore in java and it's great. The url from the blobstore will work in jplayer.

You can also set cache headers on your blob urls if you rewrite them to remove any query parameters and save yourself the costs of serving each stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM