“使用POSTMAN发布图像数据”; [英] "Post Image data using POSTMAN"
本文介绍了“使用POSTMAN发布图像数据”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数据发布到我的API。我有一个带有 image
字段的模型,其中:
I am trying to POST data to my API. I have a model with an image
field where:
image = models.ImageField()
我在我的本地邮箱上有一张要发送的图片。我可以正确发送吗?
I have an image on my local box, which I am trying to send. Am I sending it correctly?
{
"id": "3",
"uid":"273a0d69",
"uuid": "90",
"image": "@/home/user/Downloads/tt.jpeg"
}
推荐答案
那不是在邮递员上发送文件的方式。
That's not how you send file on postman. What you did is sending a string which is the path of your image, nothing more.
您应该做的是;
- 将请求方法设置为POST之后,单击正文选项卡。
- 选择表单数据。在第一行,您将看到名为key和value的文本框。在密钥上写上图片。您会看到默认情况下设置为文本的值类型。使其成为文件并上传您的文件。
- 然后选择原始并粘贴您的json文件。同样在二进制选项旁边,您会看到单击了文本。将其设为JSON。
您准备好了。
在您的Django视图,
In your Django view,
from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser
from rest_framework.decorators import parser_classes
@parser_classes((MultiPartParser, ))
class UploadFileAndJson(APIView):
def post(self, request, format=None):
thumbnail = request.FILES["file"]
info = json.loads(request.data['info'])
...
return HttpResponse()
这篇关于“使用POSTMAN发布图像数据”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文