I’ve seen and tried out playing an mp3 file that was stored in a table as a media file, as discussed in this thread: Get url of file saved in the anvil table
However, I want to access the URL via an endpoint, like
@anvil.server.http_endpoint('/audio/:input')
def call_tts(input):
r = anvil.server.HttpResponse()
r.headers['Access-Control-Allow-Origin'] = '*'
r.headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
r.headers['Access-Control-Request-Method'] = '*'
r.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
r.status = 200
audio_url = app_tables.media.get(name='tts')['audio'].url
r.body = audio_url
return r
When I access the URL on the webpage and try to play it via JavaScript, I get a 400 (Bad Request) error. Any other way to do this? I am just accessing Anvil via endpoints for this app.