The file is available as raw data in the request. How am I supposed to transform it to be saved on the disk represented by the ImageField
inside a model
.
Tried stuff:
file_ = File(request)
modelinstance.picture.save(filename, file_, save=False)
modelinstance.save()
and some variants of the above. An example on how to do this inside the django view would help.
Thanks!
Solved it like this
filename = request.GET[ 'yourfilename' ]
from django.core.files.uploadedfile import SimpleUploadedFile
file_contents = SimpleUploadedFile("%s" %(filename), request.raw_post_data)
modelinstance.picture.save(filename, file_contents, True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.