简体   繁体   English

通过Ajax从Google App Engine的Blobstore获取mp3数据

[英]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. 我正在尝试将音频文件存储在Google App Engine的Blobstore中,然后在浏览器中播放它们。 The problem I'm running into is that the data I'm getting in the browser is the actual mp3 data. 我遇到的问题是,我在浏览器中获取的数据是实际的mp3数据。 I was expecting to get a url to play the mp3 in the blobstore. 我期望获得一个URL以便在blobstore中播放mp3。 So, my question is, what do I need to change to get a url to play the blob instead of the audio data? 所以,我的问题是,我需要更改什么以获取播放blob的网址而不是音频数据?

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? 您的浏览器针对mp3请求获取什么Content-type标头? I'm guessing it's application/octet-stream 我猜这是application/octet-stream

See what Blobstore docs say about upload: 查看Blobstore文档对上传的评价:

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. 转到GAE管理页面并检查Blob Viewer,以查看在哪种内容类型下分配给了mp3文件。

The URL of the page that you're currently fetching the data from is the URL of the MP3. 您目前从获取数据的页面的URL MP3的URL。 You'll need to use a web-based player of some sort to play it. 您需要使用某种基于网络的播放器来播放它。

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

And then your example should work fine. 然后您的示例应该可以正常工作。 We use it with appengine blobstore in java and it's great. 我们将其与Java中的appengine blobstore一起使用,它很棒。 The url from the blobstore will work in jplayer. blobstore中的url将在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. 如果您重写Blob网址以删除所有查询参数并节省服务每个流的成本,则还可以在blob网址上设置缓存标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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