【发布时间】:2021-08-20 12:17:50
【问题描述】:
我决定处理正在上传的图像以获取视图中的 GPS 位置。
代码工作并保存到数据库,但我收到FileNotFoundError at /api/v1/addWaste/ [Errno 2] No such file or directory: '/tmp/tmpnsym9i2b.upload.jpg' 错误提示。
我了解到这是因为我上传的文件大于 2.5mb。
这更复杂,因为数据最终会保存在数据库中。
这是我正在使用 Django Rest Frameworks Generic Create View 的视图代码的 sn-p
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”,第 56 行,在 file_move_safe 使用 open(old_file_name, 'rb') 作为 old_file: FileNotFoundError:[Errno 2] 没有这样的文件或目录:'/tmp/tmpnsym9i2b.upload.jpg' [02/Jun/2021 11:24:51] "POST /api/v1/addWaste/HTTP/1.1" 500 179179
Thank you for your help.
【问题讨论】:
标签: django django-rest-framework django-views django-rest-viewsets