Hi i want to pass image from view to api using request,with url.
here is my code:
def processImage(request):
image=request.FILES['image']
params = {'image': image }
url='http://127.0.0.1:8000/idealweight/'
outPut_Data=requests.post(url,params=params)
//i also tried this
img=image
and then passed:
outPut_Data=requests.post(url,img)
but did not worked.and this gives error in imgFinalPro few arguments passed.
I am calling this imgFinalPro function And here I want to receive the image:
def imgFinalPro(request,img):
print(request)
# image=request.FILES['image']
# image=img
image=request.FILES['image']
How I can receive the image here? CAn use for further processing?
解决方案
Send your files inside files field not inside params.
def processImage(request):
image=request.FILES['image']
files = {'image': image }
url='http://127.0.0.1:8000/idealweight/'
outPut_Data=requests.post(url, files=files)
I Assume imgFinalPro is your controller for post request. You can't get the image as params of your controller. The image is attached with your request
def imgFinalPro(request):
print(request)
# image=request.FILES['image']
# image=img
image=request.FILES['image']