Justin
Justin

Reputation: 25

How to serve url to audio in the gae blobstore

I have audio file stored as blobs in google app engine's blobstore. I'm not sure how to get a good url to pass to the client side to play the blob. I would like to do something like the image library.

image.get_serving_url()

But, there is no audio module. So, is there a good way to get a url from a blob to play audio or even better any media?

Upvotes: 2

Views: 813

Answers (2)

Rafe Kaplan
Rafe Kaplan

Reputation: 325

I think what you're looking for is something like how S3 works, where the blobs you upload are automatically given a URL that can then be dropped directly in to the browser. Blobstore was designed to primarily give developers control over their URLs and fine grained control over access to the blobs. It does not have the facility to simply provide a URL based on, say, the blob reference. I think schuppe's answer is correct in describing what you need to do.

If you are interested in simply serving a blob to a user without any kind of authentication or restriction, it's not that hard to write a handler. The one that is in the documentation that schuppe referred you to will work ok, however, be careful, because it could open your app up to certain types of DOS attacks. Also, if you do it as the documentation does it, anyone who has one of your blob-reference strings can access any blob throughout your whole application, whether you mean to or not. Therefore you should build some additional access control around it.

Of course, if you're not concerned with controlling access to the data, that solutions is simple and will work fine.

Upvotes: 0

schuppe
schuppe

Reputation: 2033

The rendering of an image is done by the browser. It's the same for audio, the browser decides what to do with a resource you point it to. For that, you need to add the correct mime type[1] header. If the file already had the correct mime type set when being uploaded you don't need to do this manually.

As for serving the blob, you need to create a blobstore download handler: http://code.google.com/appengine/docs/python/tools/webapp/blobstorehandlers.html#BlobstoreDownloadHandler

[1] http://en.wikipedia.org/wiki/Internet_media_type

Upvotes: 2

Related Questions