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

喜夏-厌秋 提交于 2019-12-21 21:43:36

问题


I am created a Mobile application(in Titanmium).where user take pictures in mobile and i need To upload the image from mobile to django server .I am using tastypie for my Api

can any one guide me the best way to upload and save the image in server

the methods may be in pure django or using tastypie .Anything will be helpful.

and also best technique to acheieve this.


回答1:


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


来源:https://stackoverflow.com/questions/23237799/best-way-to-upload-image-from-mobile-to-django-server

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