pythondjango上传文件
Posted poorX
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pythondjango上传文件相关的知识,希望对你有一定的参考价值。
参考:https://blog.csdn.net/zahuopuboss/article/details/54891917
参考:https://blog.csdn.net/zzg_550413470/article/details/51538814
参考:https://www.cnblogs.com/linxiyue/p/7442232.html
django 文件存储:https://docs.djangoproject.com/en/dev/ref/files/storage/
django 视图接收:https://docs.djangoproject.com/en/dev/ref/files/uploads/#django.core.files.uploadedfile.UploadedFile
示例代码:
def upload_view(request): file_object = request.FILES.get(\'f\',\'\') print \'file name:\', file_object.name, \'file size:\', file_object.size, \'file content_type:\', file_object.content_type if file_object: storage_system_object = get_storage_class()(settings.BASE_DIR + \'/filestorage/\') upload_file_object = ContentFile(content = file_object.read(), name = file_object.name) storage_system_object.save(name = file_object.name, content = upload_file_object) return HttpResponse(json.dumps({\'status\':200, \'info\':""}))
上传:
# curl -F form
curl http://projecturl/path/ -F "f=@uploadfile"
以上是关于pythondjango上传文件的主要内容,如果未能解决你的问题,请参考以下文章
Alamofire 文件上传出现错误“JSON 文本未以数组或对象开头,并且允许未设置片段的选项”
AWS Elastic Beanstalk Python Django S3 Access Denied 无法上传/读取文件