Hello,
I wanted to POST an image to the SkyBiometry API. They support POST. but they said the following
"Note: in case where you want to POST images instead of specifying urls, request to the method must be formed as a MIME multi-part message sent using POST data. Each argument should be specified as a separate chunk of form data."
I have the image file on disk. How can I read it and send it in a POST request and the content type is MIME multi-part.
My current code is
How can I POST the image file in a request of multipart content type?
I wanted to POST an image to the SkyBiometry API. They support POST. but they said the following
"Note: in case where you want to POST images instead of specifying urls, request to the method must be formed as a MIME multi-part message sent using POST data. Each argument should be specified as a separate chunk of form data."
I have the image file on disk. How can I read it and send it in a POST request and the content type is MIME multi-part.
My current code is
pplx::task<void> requestTaskPost = file_stream<unsigned char>::open_istream(L"image.png").then([](basic_istream<unsigned char> fileStream)
{
// Make HTTP request with the file stream as the body.
http_client client(L"http://posttestserver.com/post.php?dir=example");
// multipart/form-data
//file_stream<unsigned char>::open_istream inputStream;
http_request req;
req.set_method(methods::POST);
req.set_body(fileStream);
req.headers().set_content_type(U("multipart"));
return client.request(req).then([fileStream](http_response response)
{
fileStream.close();
// Perform actions here to inspect the HTTP response...
if(response.status_code() == status_codes::OK)
{
std::cout << "Response OK" << std::endl;
}
});
});
What i get when i try this on the website: www.posttestserver.com, I get that 0 files uploaded.How can I POST the image file in a request of multipart content type?