Lyle Pratt
Lyle Pratt

Reputation: 5956

Save raw_post_data to FileField using Django

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

Answers (1)

Lyle Pratt
Lyle Pratt

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

Related Questions