nginx Django REST.文件上传由于FileField问题,文件大于10 Kb

nfzehxib  于 5个月前  发布在  Nginx
关注(0)|答案(1)|浏览(71)

当我尝试在Django中使用FileField将大于10 Kb的文件保存到服务器时,我从Nginx获得了500错误。
我已经配置了nginx.conf,行“client_max_body_size 20 M;”,错误从413改为500。
小于10 Kb的文件成功上传到服务器上的我的文件夹。

  • models.py*
class File(models.Model):
    name = models.CharField(max_length=255)
    file = models.FileField(upload_to='uploads/')
    uploaded_at = models.DateTimeField(default=timezone.now)

    def __str__(self):
        return self.name

字符串

  • serializers.py*
class FileSerializer(serializers.ModelSerializer):
    class Meta:
        model = File
        fields = '__all__'

  • views.py*
class FileViewSet(viewsets.ModelViewSet):
    queryset = File.objects.all()
    serializer_class = FileSerializer

h9a6wy2h

h9a6wy2h1#

我发现问题解决了。我不得不将此添加到nginx.conf:client_body_temp_path /tmp 1 2; https://github.com/CampbellSoftwareSolutions/docker-osticket/issues/34

相关问题