Best way to upload image from Mobile to Django server [closed]

白昼怎懂夜的黑 提交于 2019-12-04 17:12:27
Ambroise

There are (at least) two ways to handle file upload with Django / Tastypie :

1/ As stated in my comment :

you can make use of Tastypie's features regarding the matter. Django-tastypie: Any example on file upload in POST?

2/ You can go the Django way :

https://docs.djangoproject.com/en/1.6/topics/http/file-uploads/

A quick example (using a view) :

@csrf_exempt
def handle_uploads(request):
    if request.method == 'POST':
        uploaded_file = request.FILES['file']
        file_name = uploaded_file.name
        # Write content of the file chunk by chunk in a local file (destination)
        with open('path/to/destination_dir/' + file_name, 'wb+') as destination:
            for chunk in uploaded_file.chunks():
                destination.write(chunk)

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