BigBerger
BigBerger

Reputation: 1803

Django HttpResponse to online MP3 file

I was wondering if there was a way to encode the contents of an online MP3 file (In this example from an Amazon S3 server) and return it as a Django HttpResponse.

Note - I do not want to use HttpResponseRedirect, I don't want to plainly return the Amazon URL and have to allow public access on my S3 servers. This would be a huge security risk. I would like to have my Django server act as a sort of 'middle man' and serve the audio stream content to the user without the user interacting with the S3 server at all.

Thank you in advance for your help.

Upvotes: 1

Views: 1486

Answers (2)

power
power

Reputation: 331

This is not a good idea, to serve static files with Django HttpResponse.
Why don't you set up Nginx proxy? Check this: https://coderwall.com/p/rlguog

Upvotes: 0

Audrey-Rose
Audrey-Rose

Reputation: 73

I haven't personally tried this out, but you could probably get the mp3 file via the backend, send the data to an HttpResponse and set streaming=True so it'll output the file properly.

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

or the object that does the work (as mentioned by Brian)

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

Upvotes: 2

Related Questions