0

I decided to process the image being uploaded to get the GPS location in views.

the code work and saves to the db but I get prompted to with a FileNotFoundError at /api/v1/addWaste/ [Errno 2] No such file or directory: '/tmp/tmpnsym9i2b.upload.jpg' error.

I learnt that this is because my upload is larger than 2.5mb.

It is more complicated because the data ends up getting saved in the db.

here is snippet of my views code I am using Django Rest Frameworks Generic Create View

    def create(self, request, *args, **kwargs):
        
        serializer = self.get_serializer(data=request.data)
        # file = request.FILES['files']
        serializer.is_valid(raise_exception=True)
        
        # geospatial fields
        picture=(serializer.validated_data['field_picture'])
        print(picture.temporary_file_path())
        
        latitude, longitude = get_coordinates(picture)

        serializer.validated_data['latitude']= latitude
        serializer.validated_data['longitude'] = longitude

        # geom
        serializer.validated_data['geom'] = Point(latitude,longitude)
        serializer.save()

        if serializer.save():
            return Response({
                            'Response': 'Waste point Created suceesfully',
                            'payload': serializer.data 
            })
        ```


Here is a copy of my terminal debug message 

/.local/share/virtualenvs/Backend-bhMgLIsh/lib/python3.8/site-packages/django/core/files/move.py", line 56, in file_move_safe with open(old_file_name, 'rb') as old_file: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpnsym9i2b.upload.jpg' [02/Jun/2021 11:24:51] "POST /api/v1/addWaste/ HTTP/1.1" 500 179179

Thank you for your help.
Philip-kio
  • 11
  • 1
  • 1

1 Answers1

0

So Django has a way of handling large file uploads, it passes it through a tmp folder on your local machine.

So how solved my challenge was to preprocess everything in the models.py using the save method for the Table is created.

hence everything 9my logic) was handled just before it is saved in the DB.

It works fine.

Philip-kio
  • 11
  • 1
  • 1