1

I'm trying to upload a picture to my rest API on my server through the following code (using cpprest libraries):

int uploadActiveUserImage(std::string *fileName)
{
auto fileStream = std::make_shared<istream>();
// Open stream to output file.
      pplx::task<void> requestTask = fstream::open_istream("activeUser.png").then([=](istream frame)
      {
         *fileStream = frame;
         // Create http_client to send the request.
         auto client = http_client{U(".....website..../api/activeUser/image")};
         //auto client = http_client{U("http://localhost/smartmirrorAPI/smartmirrorAPI/api/activeUser/image")};
        // Build request URI and start the request.
        auto query = uri_builder()
          .to_string();

        return client.request(methods::PUT, query, *fileStream);

})

This code works when sending pictures to the microsoft faces api and when sending to localhost but not to my server. I am able to send a picture to my api(on my server) using the postman extension on chrome so there are no issues with file permissions.

This is a snippit of my api code on the server which handels the request.

case 'PUT':
        $data = file_get_contents("php://input");
        if (is_null($data)) {
            header('HTTP/1.1 400 Bad Request');
            header('Content-Type: application/json');
            var_dump($data);
            return;
        }
        $result = file_put_contents("activeUser.png", $data); //Where to save the image on your server
        //var_dump($data);
        echo($result);

$data is an empty string when sending to the api on the server.

Please help, I have been looking for hours.

Thank you, Robbert

Robbert D
  • 11
  • 4

0 Answers0