I have some sound files in a couchdb database (not related to web2py). My web2py application has access to this database, and I want to stream the sound files so that they can be listened with the HTML audio tag, like this:
<audio src="http://www.myserver.com/.../track06.mp3" preload="auto"></audio>
I am planning to do this streaming based on this suggested example:
def streamer():
import os
path=os.path.join(request.folder,'private','largefile.mpeg4')
return response.stream(open(path,'rb'),chunk_size=4096)
But I have some open questions:
- My filename is not in the local filesystem, but in a
couchdbdatabase, accessible via REST. How can I open that for streaming? - What kind of request will the audio tag send when it is activated, GET/POST/…? Can this be handled with
web2py?
Basically, I would like to know if somebody has a working example of streaming couchdbattachments via web2py.
The solution I am using now is this:
The
get_doc_urlfunction is just creating a url to access the attachment.The content_type is fixed, but this should be obtained from the attachment (I do not yet know how to do this).