Javascript发布请求无法将文件发送到端点

时间:2020-04-19 05:07:47

标签: javascript post django-rest-framework axios

我正在发送包含文件的 Axios 帖子:

const sendFilePreactivation = (file) => {
  let requestString = inventoryApiString + "preactivations_logs/";

  let form = {
    preactivations_file: file,
  };
  const header = getAuthHeaderMedia()
  return axios.post(requestString, form, header)
    .then((Response) => {
      return {
        newActionPreactivation: Response.data,
        message: null,
      };
    })
    .catch((Error) => {
      return getErrorMessage(Error);
    });
};

您可以在此处看到标题:

enter image description here

问题是 Django Rest Framework 端点返回此错误: enter image description here

含义No file was sent。通过调试,我知道发送的表单包含[object File]

这是捕获发帖请求的DRF视图:

class PreactivationLogViewSet(CustomModelViewSet):
    permission_classes = (permissions.IsAuthenticated,)
    queryset = models.PreactivationLog.objects.all()
    serializer_class = serializers.PreactivationLogSerializer
    filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter,)
    search_fields = ('id',)
    filter_fields = ('id',)

我不知道我在做什么错。

0 个答案:

没有答案