In my C++ program I download images (album art etc.) from over the air radio signals and need to save the images in a public web folder such as /var/www/html
to serve later via a web page.
I'm developing on Ubuntu 16.04 but eventually, the app will be deployed on Raspberry Pi. My program is a WebSocket Server using the library uWebsockets and also talks to a radio tuner via unix sockets. The app is supposed to auto-start at boot time and act as WebSocket server on a specific port.
Here's the code to save the image array -
std::string filePath = "/var/www/html/output1.jpg";
std::ofstream ofs(filePath);
ofs.write(image->c_str(), image->size()); // image is JPEG image as string array
ofs.flush();
ofs.close();
Above code won't create file at the specified location, however it will work if the path is just "output1.jpg"
.
Clearly, my app doesn't have permission to write to /var/www/html
. Is there any way to solve this using standard c++ or boost?
Thanks