我的Django Rest API views.py:
# encoding: utf-8
from fileupload.response import JSONResponse, response_mimetype
from fileupload.models import *
from rest_framework.views import *
from rest_framework.parsers import *
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
"""A simple API for file upload."""
class FileUploadView(APIView):
authentication_classes = ()
@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super(FileUploadView, self).dispatch(request, *args, **kwargs)
def put(self, request):
print "xxx:", request
try:
psfile = MyFile.objects.create(file=request.FILES['file'])
psfile.save()
data = {'files': 'testing'}
response = Response(data)
except Exception as e:
print "Exception when put file:", e
data = { 'error' : str(e)}
response = Response(data)
return response
setting.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ()
}
我在Postman中使用Postman Interceptor进行PUT。 试图将文件作为表单数据放在正文中。 但由于以下错误而失败:
Could not get any response
There was an error connecting to https://ip/projectname/api/upload/.
Why this might have happened:
1. The server couldn't send a response:
Ensure that the backend is working properly
2. SSL connections are being blocked:
Fix this by importing SSL certificates in Chrome
3. Cookies not being sent: Use the Postman Interceptor extension
4. Request timeout:
Change request timeout in Settings > General
有什么想法吗?提前致谢。
更新
https://github.com/postmanlabs/postman-app-support/issues/506
http://blog.getpostman.com/2014/01/28/using-self-signed-certificates-with-postman/