poorX

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

参考: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"

 

posted on 2018-07-10 16:58  poorX  阅读(229)  评论(0编辑  收藏  举报