How do I add a key when posting a image?

I have a issue when posting a file to a server developed by python flask, but always failed with a key error that the key "file" cannot found in request. My question is how to add the key "file" in web post file method?
here is the blocks:

here is the code in server:

You can see that in the server post method, it will get a file object from request.files["file"], but the request does not has this key.

Here is the response error:

400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'file'

I also captured the request raw data:

  • Post from inventor:

Welcome any suggestions. Thanks.

Is the server expecting multipart? You cannot send multipart with the web component.

Thanks, so any workaround recommend?

Use php instead ?

For example:

It may also be that using the customWebView you can upload your files...

If I'm not mistaken, there are extensions out there that can encode images in base64. You may consider using such a method to "stringify" your image before POSTing it as text.

the request header must be a list of key value pairs, i.e. a list of lists...
you currently only have a key value pair, i.e. a simple list


1 Like

Many thanks for the suggestions. I resolved this issue by updating the python server code. use "" to replace with "request.files['file']", after that, key is not required when posting any more.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.