-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multipart formdata reader decode error if filename is not specified #3600
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #3242 (Error), #3064 (multipart BodyPartReaderPayload filename wrong), #2201 (Client: FormData._gen_form_data ignores filename, explodes), #3090 (Remove reader parameter from request.multipart()), and #67 (fix header encoding error). |
Could you provide a minimal reproducible example for demonstrating the problem? |
server: import asyncio
import aiohttp
from aiohttp import web
async def hnd(request: web.Request):
data = await request.post()
img = data['img']
if hasattr(img, "file"):
cont = img.file.read()
else:
cont = img
print(cont[:100])
app = web.Application()
app.add_routes([web.post('/', hnd)])
web.run_app(app) client: #include <string>
#include <fstream>
#include <streambuf>
#include <curl/curl.h>
using namespace std;
int main(int ac, char**av) {
ifstream f(av[1]);
string cont{istreambuf_iterator<char>(f), istreambuf_iterator<char>()};
auto req = curl_easy_init();
curl_easy_setopt(req, CURLOPT_PORT, 8080);
curl_easy_setopt(req, CURLOPT_URL, "localhost");
curl_httppost *post=nullptr, *last=nullptr;
curl_formadd(&post, &last,
CURLFORM_PTRNAME, "img",
CURLFORM_PTRCONTENTS, cont.c_str(),
CURLFORM_CONTENTLEN, cont.size(),
CURLFORM_END
);
curl_easy_setopt(req, CURLOPT_HTTPPOST, post);
// curl_easy_setopt(req, CURLOPT_POST, post);
auto res = curl_easy_perform(req);
printf("curl res %i\n", res);
curl_easy_cleanup(req);
} Compile client: Error:
|
The request is missing a content-type. It works fine when adding:
|
Long story short
I have a client that uses libcurl and a server which uses aiohttp. The client sends multipart formdata where one of the forms is binary (image). aiohttp tries to decode it as string
If you use curl utility
curl -v -s -X POST -F "image=@img" http://myserver.com
it automatically substitutes filename. libcurl API on the other hand doesn't let you specify filename unless you upload real file as well as content-type.So there is no way to pass image using libcurl if this image doesn;t exist as a file on filesystem
Link to the line where exception occurs
aiohttp/aiohttp/web_request.py
Line 525 in cc2a522
Expected behaviour
Every form field is represented as bytes (or Bytestream) with headers.
Your environment
centos 7 on both sides
PS this requires API modification
The text was updated successfully, but these errors were encountered: