tanky
tanky

Reputation: 115

appengine and html5 audio

I'm just trying to figure out how to use the blobstore and HTML5 audio.

My code is only slightly modified from working code, so it cant need major changes.

class data(webapp2.RequestHandler): 
def get(self):
    a = db.GqlQuery("SELECT * FROM UserPhoto")
    blob = a[1].blob_key


    self.redirect('/Serve/%s' % blob.key())



class ServeHandler(Handler, blobstore_handlers.BlobstoreDownloadHandler):
def get(self, audio_key):
    if not blobstore.get(audio_key):
        self.error(404)
    else:
        self.send_blob(audio_key)
        self.redirect('/music')

class music(Handler):
def get(self):
    self.render("music.html")

and this is the HTML where the audio will be played:

<audio controls="controls">
<source src="/Serve/%s"/>
Your browser does not support the audio element.

and the error is

"GET /Serve/%s HTTP/1.1" 404 -

Upvotes: 0

Views: 154

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600051

You don't seem to have put the actual key variable in the HTML. You just have /serve/%s which is obviously wrong - Django templates don't even use Python string substitution, let alone the fact that you haven't given it anything to substitute.

You need to pass the blob key to the template from the get handler, then reference it with <source src="/Serve/{{ blob_key }}"/>.

Upvotes: 3

Related Questions