'Foscam IP camera: get snapshot

I'm trying to get a snapshot from my Foscam FI9816P camera. I'm using the following address:

http://[IPADDRESS]:[PORT]/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=[USER]&pwd=[PWD]

and this works fine from the browser, showing the image snapshot.

Programmatically, I've been using in the past another camera, providing the ("raw") JPG image as the response:

using (WebClient client = new WebClient())
{
    byte[] JpgFile = null;
    JpgFile = client.DownloadData(sWebCam);
    // ...
}

Now, this new camera is providing a "HTML page" as the response, containing the image link as an embedded img tag:

<html><body><img src="../snapPic/Snap_20150729-164352.jpg"/></body></html>

Now, the point is that if I point to the image address:

http://[IPADDRESS]:[PORT]/snapPic/Snap_20150729-164352.jpg

I get a 404 - Not found error. I can't see what is going on "behind the scenes" to get the image; above all, I don't know how to get the "raw" image JPG in C#.

Edit [1]:

I got this working, parsing the image tag inside the html, and sending a second "GET" request:

sWebCam = String.Concat("http://", cConfig.WebcamIpAddress, "/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=[USER]&pwd=[PWD]");
try
{
    JpgFile = client.DownloadData(sWebCam);

    string sTmp = System.Text.Encoding.Default.GetString(JpgFile);
    sTmp = sTmp.Substring(sTmp.IndexOf("<img src=\"") + "<img src=\"".Length);
    sTmp = sTmp.Substring(0, sTmp.IndexOf("\"/>"));
    sTmp = sTmp.Replace("..", "");

    sWebCam = string.Concat("http://", cConfig.WebcamIpAddress, sTmp);
    JpgFile = client.DownloadData(sWebCam);
}

So, i'm wondering why accessing the final image address from the browser (http://[IPADDRESS]:[PORT]/snapPic/Snap_20150729-164352.jpg) is giving out a 404. This is the original reason why I was confused...



Solution 1:[1]

I faced the same issue, as snapPicture2 function was supposed to return the "raw" image (differently from snapPicture, returning instead it wrapped in an HTML page), but changed its behaviour in FI9816P firmware 1.9.2.12 due to an alleged bug (reference: http://foscam.us/forum/fi9816p-broken-snappicture2-bug-t13482.html).

In my existing system I required the raw image, this led me to further investigation having as output a NodeJS module (which btw is available on GitHub: https://github.com/andreatondo/foscam-snapshot-nodejs) to workaround the problem.

To answer your question, it appears that Foscam saves the image in /snapPic/ path just for the time required to serve your request, and then deletes it. This is why it returns a 404 when you try to use the link in HTML page.

This just to confirm that your approach is the right one, at least until Foscam fixes the issue on a next firmware update.

Solution 2:[2]

Use wget for download :

wget -m -p -k "http://192.168.8.108:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=XXX&pwd=XXX"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrea Tondo
Solution 2 cursorrux