在Django Rest中处理从前端阵列发送的后端图像文件
我不确定后端是否与之有任何关系,即这必须由前端来解决。我有一个post API,其中的数据是这样发送的在Django Rest中处理从前端阵列发送的后端图像文件,django,api,django-rest-framework,axios,form-data,Django,Api,Django Rest Framework,Axios,Form Data,我不确定后端是否与之有任何关系,即这必须由前端来解决。我有一个post API,其中的数据是这样发送的 { "merchant": 2, "category": [ 7 ], "brand":7 , "name":"picture55
{
"merchant": 2,
"category": [
7
],
"brand":7
, "name":"picture55test",
"best_seller":true,
"top_rated":false,
"collection":10,
"description":"abc",
"featured": false,
"availability": "in_stock",
"warranty": "no_warranty",
"rating":5,
"picture": [],
"services": "cash_on_delivery",
"variants": [
{
"product_id": "OAXWRTZ_12C",
"price": "500.00",
"size": "not applicable",
"color": "not applicable",
"variant_image": null,
"quantity": 10,
"variant_availability": "available"
},
{
"product_id": "OGROUPIRZ_12C",
"price": "888.00",
"size": "not applicable",
"color": "not applicable",
"variant_image": null,
"quantity": 10,
"variant_availability": "available"
}
]
}
我在这里尝试创建一个产品对象,同时创建变体对象。问题是,前端无法从表单数据中的变量数组发送图像,而变量数组是vairant_图像
有效负载头如下所示
正如您可以看到的那样,变量字段就像一个对象,而不是一个表单数据。我不知道如何处理这个后端
我的观点是这样的。我使用了FormParser和Multipartparser,以防它处理图像
我只是不知道这是从前端还是后端处理。此外,我们无法将上述数据转换为表单数据,因为其中包含一个变量数组
class ProductAddAPIView(CreateAPIView):
permission_classes = [IsAuthenticated]
parser_classes = [MultiPartParser,JSONParser,FormParser]
queryset = Product.objects.all()
serializer_class = AddProductSerializer