POST an image file to REST API (SkyBiometry)

Nov 5, 2014 at 12:36 PM
Edited Nov 5, 2014 at 1:11 PM
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
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?
I didn't find a clear example on reading any type of files from Disk.
Coordinator
Nov 6, 2014 at 5:46 PM
Hi mohamedselim,

I haven't used the SkyBiometry API so I can't give you exact code. It sounds like what you need to do is build up the HTTP request body as a multi-part MIME type where each chunk of the multi-part message is one of the photos you want to do face detection on. This can be done by writing each chunk of the multi-part message to the stream you specify to http_request::set_body(...).

I also responded to the other discussion thread you posted to.

Steve