python - Django HttpResponse 对在线 MP3 文件

标签 python django httpresponse audio-streaming

我想知道是否有一种方法可以对在线 MP3 文件的内容进行编码(在本例中来自 Amazon S3 服务器)并将其作为 Django HttpResponse 返回。

注意 - 我不想使用 HttpResponseRedirect,我不想简单地返回 Amazon URL,并且必须允许在我的 S3 服务器上进行公共(public)访问。这将是一个巨大的安全风险。我想让我的 Django 服务器充当某种“中间人”的角色,向用户提供音频流内容,而无需用户与 S3 服务器交互。

预先感谢您的帮助。

最佳答案

我还没有亲自尝试过这一点,但您可能可以通过后端获取 mp3 文件,将数据发送到 HttpResponse 并设置 Streaming=True,以便它正确输出文件。

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.streaming

或完成工作的对象(如布莱恩提到的)

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.StreamingHttpResponse

关于python - Django HttpResponse 对在线 MP3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25612790/

相关文章:

python - 如何添加到从另一个类继承的 python 类的初始定义?

python - 获取 : invalid input syntax for uuid: "" when using django-uuidfield as primary key for a model

Django 在 TabularInline View 中禁用编辑(但允许添加)

javascript - Node js不响应请求远程服务器

spring-boot - Spring Boot - Rest Controller 响应两个 JSON 对象

c# - 将 html 响应内容的字符集设置为 1252

python - 如何多次运行相同的TestSuite unittest texttestrunner

python - 在python中向字符串添加空字符

python - 匹配 3 个大写字母后跟一个小写字母后跟 3 个大写字母的正则表达式?

python - PyCharm 中 Django 文档字符串中未解析的引用