Error loading a video and creating an object in django

1

My role in Django will receive a video from my site, it is working normally. Then I created the function create :

   def create(self, request):
       Video.objects.create(file=request.data['file'], creator=self.request.user)
       return Response('ok')

I'll set the function my way. But when I load a file from my disk: request.data['file'] = open('/home/developer/Pictures/teste.webm') You're giving me the following error:

   def create(self, request):
       request.data['file'] = open('/home/developer/Pictures/teste.webm')
       Video.objects.create(file=request.data['file'], creator=self.request.user)
       return Response('ok')

OutPut: *** TypeError: readonly attribute

So I checked the type of my variables.

(Pdb) type(request.data['file'])
<class 'django.core.files.uploadedfile.InMemoryUploadedFile'>
(Pdb) request.data['file'] = open('/home/developer/Pictures/teste.webm')
(Pdb) type(request.data['file'])
<type 'file'>

Ok, I know my variables have different types, but as I make my local file type: <class 'django.core.files.uploadedfile.InMemoryUploadedFile'>

    
asked by anonymous 07.06.2018 / 14:57

0 answers