#导入上传文件夹配置 from mydjango.settings import UPLOAD_ROOT import os #文件上传通用类 class UploadFile(APIView): def post(self,request): #接收参数 myfile = request.FILES.get('file') #建立文件流对象 f = open(os.path.join(UPLOAD_ROOT,'',myfile.name.replace('"','')),'wb') #写入 for chunk in myfile.chunks(): f.write(chunk) f.close() return Response({'filename':myfile.name.replace('"','')})