-1

I am doing rotate operation on camera using CURL library.

Here is what I've done so far:

#include <iostream>         // For std::cerr
#include <string>           // For std::string,getline(),c_str()

#include <curl/curl.h>      // For curl library functions like curl_easy_setopt,curl_easy_perform etc.

class camera_image_rotate {
    CURL *curl = curl_easy_init();
    std::string ipaddress,username,password,url;
    int rotation;
    CURLcode res;   
    public:
    camera_image_rotate(int x) : rotation(x) {
        std::cout<<"Enter ip address: ";
        getline(std::cin,ipaddress);
        std::cout<<"Enter username: ";      
        getline(std::cin,username);
        username+=":";
        std::cout<<username<<'\n';
        std::cout<<"Enter password: ";
        getline(std::cin,password);
        password+="@";
        std::cout<<password<<'\n';
        ipaddress+="/axis-cgi/jpg/image.cgi?rotation=";
        ipaddress+=std::to_string(rotation);
        std::cout<<ipaddress<<'\n';
        url=username+password+ipaddress;
    }
    void rotate() {
        if(curl) {
            res=curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
            res=curl_easy_perform(curl);
            if(res!=CURLE_OK)
                std::cerr<<"Oops, Invalid IP";
        }
        else {
            std::cerr<<"Something went wrong";
        }
    }
    ~camera_image_rotate() {
        if(res==CURLE_OK)
            curl_easy_cleanup(curl);
    }
};

int main() {
    camera_image_rotate s(90);
    s.rotate();
}

Now, the problem I am facing is that when I execute this program it tries to print the rotated image on console so I am getting some completely unreadable output. So, I want to redirect the output of this program to either *.jpg or *.png file. How do I achieve that ? I've referred documentation about CURL on their official site but I didn't find anything useful.

I am using ubuntu OS & clang++ 3.8.0 compiler.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222
Destructor
  • 14,123
  • 11
  • 61
  • 126

1 Answers1

2

You're probably looking for the CURLOPT_WRITEFUNCTION callback that gets called with all the data from the download. (A little piece at a time.)

In simpler cases you may also get away with the default write function and simply set CURLOPT_WRITEDATA to a file.

You may also find some additional understanding for how the callback works by looking at the examples, like getinmemory.c - that uses the callback to receive the entire contents of a transfer into memory.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222