SOLVED: Download the image from THETA Camera in Client Mode

Hello

I tried download the image from THETA camera with this php code :

error_reporting(E_ALL); 
  ini_set( 'display_errors','1');
  
  $url ="http://192.168.254.124/osc/commands/execute";
  $username = 'THETAYN10113693';
  $password = '10113693';
 // $parameters json_encode(array("fileType" => "image", "entryCount" => 1, "maxThumbSize" => 0));
  $Body = json_encode(array('name' => 'camera.listFiles', 'parameters' => array("fileType" => "image", "entryCount" => 1, "maxThumbSize" => 0)));
  $options = array(
          CURLOPT_URL            => $url,
          //CURLOPT_HEADER         => true,
          CURLOPT_VERBOSE        => true,
          CURLOPT_RETURNTRANSFER => true,
          CURLOPT_FOLLOWLOCATION => true,
          CURLOPT_SSL_VERIFYPEER => false,    // for https
          CURLOPT_USERPWD        => $username . ":" . $password,
          CURLOPT_HTTPAUTH       => CURLAUTH_DIGEST,
          CURLOPT_POST           => true,
          CURLOPT_HTTPHEADER     => array('Content-Type:application/json'),
          CURLOPT_POSTFIELDS     => $Body
     
  );
  
  $ch = curl_init();
  
  curl_setopt_array( $ch, $options );
  
  $raw_response  = curl_exec( $ch );

 // echo json_encode($raw_response);  
 $total_data =json_decode($raw_response,true);

 $fileUrl = $total_data['results']['entries'][0]["fileUrl"];
 $filename = $total_data['results']['entries'][0]["name"];

//$mime = "image/jpg";


$data = file_get_contents($fileUrl);
 header('Content-Type: image/jpeg');
 header('Content-Disposition: attachment; filename="'.$filename.'"');
 header("Content-Transfer-Encoding: binary");
 header('Pragma: no-cache');
 header("Content-Length: ".strlen($data));
 $data = file_get_contents($fileUrl);
 exit($data);


that is worked and image has been downloaded but when I try open this image I got message :

its appears that we don’t support this file format

and image dont open

I think that is not correct code to download images from Camera. maybe when Camera need Authentication maybe need another code to images download or maybe this code not work with this images type, which made by this Camera. I dont know I hope get Help

thanks so much

I don’t know PHP. However, I will try and supply some information.

The RICOH THETA image is a standard JPG image. You can replicate the camera functionality of providing a JPG image with HTTP with this:

If you can get an image from lorem picsum, but not with the THETA, then please post the error log from your debug console with the camera.

You can disable digest authentication with this:

Notice of website closure

When you get the image from the camera with a GET, are you using Digest Auth?

          CURLOPT_USERPWD        => $username . ":" . $password,
          CURLOPT_HTTPAUTH       => CURLAUTH_DIGEST,

Have you tried your download code with and without digest authentication (meaning, you disabled it).

Does your download code work when you have the camera in access point mode?

There’s some discussion about reading and writing files with PHP.

PHP: fpassthru - Manual

Once you get the fileUrl, can you get the file from your debug console?

Example

Saving to Windows file system

okay proplem is Resolved

this proplem was because of authentication

i added only this two lines to PHP code :

and then picture is normal opened after Download

thank you so much

2 Likes

thanks for posting the solution.

When you use Client Mode, you must use Digest Authentication for every call to the camera, even the http GET to the image resource.

Do you need the authentication in your work environment? Do you plan on having more than one camera? Are there other people in the work environment that could potentially use the app to access the wrong camera.

1 Like