Mox*_*Mox 5 python django django-file-upload django-rest-framework
问题如上所述。虽然有很多关于使用 django Rest 框架上传文件的教程。没有人提到它的可恢复版本。我需要在一个项目中实现它。有人可以向我指出一些资源或提供示例代码吗?非常感谢您的帮助。
更新
这是我到目前为止所得到的。
视图.py
class FileUploadView(views.APIView):
parser_classes = (FormParser, MultiPartParser)
def put(self, request, format=None):
file_obj = request.data['file']
self.handle_uploaded_file(file_obj)
return Response(status=204)
def handle_uploaded_file(self, ufile):
filename = "{0}/{1}".format(settings.MEDIA_ROOT, ufile)
with open(filename, "wb+") as target:
for chunk in ufile.chunks():
target.write(chunk)
Run Code Online (Sandbox Code Playgroud)
卷曲命令
curl -H "Content-Disposition: attachment; filename=try.py" -X PUT -F "file=@try.py" http://localhost:8000/api/fileupload/?filename=testing
Run Code Online (Sandbox Code Playgroud)
尝试.py
from django.test import TestCase
# Create your tests here.
Run Code Online (Sandbox Code Playgroud)
下一部分是如何使其可恢复。
| 归档时间: |
|
| 查看次数: |
1371 次 |
| 最近记录: |