使用Django将raw_post_data保存到FileField [英] Save raw_post_data to FileField using Django
本文介绍了使用Django将raw_post_data保存到FileField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用Python/Django将一些原始Post数据(request.raw_post_data)直接保存到FileField中.到目前为止,我发现的所有信息都无法保存RAW数据.
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.
更具体地说,原始数据是使用Flash从麦克风记录的波形数据.
More specifically, the raw data is the wave data recorded from a Mic using Flash.
有人可以告诉我这是怎么做的吗?
Can someone please show me how this is done?
谢谢!
推荐答案
好.我想到了.您可以像这样使用SimpleUploadedFile:
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)
这篇关于使用Django将raw_post_data保存到FileField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文