I trying to pass some files through djangorest framework and while trying to do so, I am facing error
'list' object has no attribute 'name'
my views.py
from django.shortcuts import render
from rest_framework import serializers
from rest_framework import viewsets
from rest_framework import status
from rest_framework.response import Response
from restfilesupload.serializers import FileSerializer
class FileUploadViewSet(viewsets.ViewSet):
def create(self, request):
serializer_class = FileSerializer(data=request.data)
if request.method == 'POST':
if 'file' not in request.FILES or not serializer_class.is_valid():
return Response(status=status.HTTP_400_BAD_REQUEST)
else:
handle_uploaded_file(request.FILES.getlist("file"))
return Response(status=status.HTTP_201_CREATED)
def handle_uploaded_file(f):
with open(f.name, 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
class Meta:
fields = ['pk' , 'file']
my serializers.py
from rest_framework import serializers
class FileSerializer(serializers.Serializer):
file = serializers.FileField(max_length=None, allow_empty_file=False)
My error :
Here is the github repo for the project ..
github
where currently I can upload single file just fine but the problem arises while trying to upload multiple images
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…