Save raw_post_data to FileField using Django

I need to save some Raw Post data (request.raw_post_data) directly to FileField using Python / Django. All the information that I have found so far does not help when saving RAW data.

More specifically, the raw data is wave data recorded from a microphone using Flash.

Can someone please show me how this is done?

Thanks!

+2
source share
1 answer

Ok I understood. You can use SimpleUploadedFile as follows:

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) 
+6
source

Source: https://habr.com/ru/post/1441305/


All Articles