Save raw_post_data to FileField using Django

人盡茶涼 提交于 2019-12-08 02:27:50

问题


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!


回答1:


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)


来源:https://stackoverflow.com/questions/6232089/save-raw-post-data-to-filefield-using-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!