【问题标题】:Google Cloud Storage Signed URL with Google App Engine using Django with Search Filters使用带有搜索过滤器的 Django 和 Google App Engine 的 Google Cloud Storage 签名 URL
【发布时间】:2020-07-06 00:29:54
【问题描述】:

我有以下带有相关字段的模型和一个所有模型字段都正确返回的 api。

class VideoEntityFilterSerializer(serializers.ModelSerializer):
    class Meta:
        model = Entity
        fields = ('uuid', 'description', 'url', 'segment_start', 'segment_end', 'confidence', 'username', 'userid', 'videouuid', 'videotitle')

class VideoEntityList(generics.ListAPIView):
    model = Entity
    serializer_class = VideoEntityFilterSerializer
    queryset = Entity.objects.all()
    filter_backends = [filters.SearchFilter]
    search_fields = ['videouuid', ]
    pagination_class = StandardResultsSetPagination

我需要添加一个动态字段“签名 url”,以便在请求时为特定授权用户提供访问权限以及实际的 google 存储 url。

我怎样才能做到这一点?

【问题讨论】:

    标签: django google-cloud-platform django-rest-framework google-cloud-storage google-app-engine-python


    【解决方案1】:

    我认为正确的答案是下面使用 SerializerMethodField :

    class VideoEntityFilterSerializer(serializers.ModelSerializer):
      signed_url = serializers.SerializerMethodField('get_signed_url')
    
      def get_signed_url(self, foo):
          return foo.name == "bar" 
    
      class Meta:
        model = Entity
        fields = ('uuid', 'description', 'url', 'segment_start', 'segment_end', 'confidence', 'username', 'userid', 'videouuid', 'videotitle', 'signed_url')
    

    【讨论】:

      猜你喜欢
      • 2014-03-22
      • 2016-07-28
      • 2015-08-30
      • 1970-01-01
      • 2016-05-22
      • 2022-01-24
      • 2014-01-16
      • 1970-01-01
      • 2015-05-14
      相关资源
      最近更新 更多