我正在发送包含文件的 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);
});
};
您可以在此处看到标题:
问题是 Django Rest Framework 端点返回此错误:
含义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',)
我不知道我在做什么错。