简体   繁体   中英

how i can pass image as argument in python request along with url as 2nd argument?

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM