Reputation: 5956
I need to save some Raw Post Data (request.raw_post_data) straight to a FileField using Python/Django. All the information I have found so far is not helpful for saving RAW data.
More specifically, the raw data is the wave data recorded from a Mic using Flash.
Can someone please show me how this is done?
Thanks!
Upvotes: 2
Views: 2739
Reputation: 5956
Ok. I figured it out. You can use SimpleUploadedFile like this:
if request.method == 'POST':
from django.core.files.uploadedfile import SimpleUploadedFile
object = Model.objects.get(pk=1)
file_contents = SimpleUploadedFile("%s.mp3" % "myfile", request.raw_post_data, "audio/mp3")
object.audio.save("%s.mp3" % "myfile", upfile, True)
Upvotes: 7