Upload pano Image using street View Publish API

核能气质少年 提交于 2019-12-06 15:12:03

问题


When I am making upload using the the given street View API

Request an Upload URL
        $ curl --request POST \
        --url 'https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=YOUR_API_KEY' \
        --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
        --header 'Content-Length: 0'

Upload the photo bytes to the Upload URL
        $ curl --request POST \
        --url 'UPLOAD_URL' \
        --upload-file 'PATH_TO_FILE' \
        --header 'Authorization: Bearer YOUR_ACCESS_TOKEN'

But its not Working..

Its giving me the error No file found in request.

Can anybody please help me regarding this ..

Thank you in Advance.


回答1:


To Get the upload URL I solved By this way

$cur_upload_url = curl_init();

  curl_setopt_array($cur_upload_url, array(

   CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo:startUpload?key=XXXXXXXXXXX" ,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_ENCODING => "" ,
   CURLOPT_CUSTOMREQUEST => "POST",
   CURLOPT_HTTPHEADER => array(
     "authorization: Bearer $access_token",
        "content-type: application/json",
        "Content-Length: 0"
        ), 
  ));

  $response = curl_exec($cur_upload_url);
  $re = '/https?:\/\/[^"]*/';
  $str = $response;
  preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
  $upload_url = $_SESSION['UploadRef'] = $matches[0][0];

  echo $upload_url;

Upload the photo bytes to the Upload URL

$cmd = exec('curl --request POST \--url "'. addslashes($upload_url) .'" \--upload-file "'.$imagePath.'" \--header "Authorization: Bearer '. addslashes($access_token) .'" ');

Then Uplaod the meta data of photo

$curl_meta = curl_init();

  curl_setopt_array($curl_meta, array(
    CURLOPT_URL => "https://streetviewpublish.googleapis.com/v1/photo?key=XXXXXXXXXXXXXXXX",
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => '{
                    "uploadReference":
                    {
                      "uploadUrl": "'.$upload_url.'"
                    },
                    "pose":
                     {
                       "heading": 95.0,
                       "latLngPair":
                       {
                         "latitude": '.$latVal.',
                         "longitude": '.$langVal.'
                       }
                    },
                    "captureTime":
                    {
                      "seconds":  '.$time_stamp.'
                    },
                  }',

    CURLOPT_HTTPHEADER => array(
       "authorization: Bearer $access_token",
       "content-type: application/json"
    ),

  ));


      $response_meta = curl_exec($curl_meta);
      $response_json = json_decode($response_meta, true);
      // $photoID = $response_json['photoId']['id'];
      // echo $photoID;


      if(curl_errno($curl_meta)){
        // this would be your first hint that something went wrong
        die('Couldn\'t send request: ' . curl_error($curl_meta));
      }else{
        //check the HTTP status code of the request.
        $resultStatus = curl_getinfo($curl_meta, CURLINFO_HTTP_CODE);
        if($resultStatus != 200){
          die('Request failed: HTTP status code: ' . $resultStatus);
        }else{
          $photoID = $response_json['photoId']['id'];
          //insert google publish information into db table

        }

      }



      curl_close($curl_meta);

From here you will get the photo ID.

After getting the Photo iD publish is successful.




回答2:


If anyone looking some option to upload via node.js server:

import { exec } from 'child_process';
await new Promise((resolve, reject) => {
  const uploadCmd = `curl --request POST \ --url "${uploadUrl}" \ --upload-file "${__dirname}/360.jpg" \ --header "Authorization: Bearer ${accessToken}" `;
  exec(uploadCmd, (err, stdout, stderr) => {
    if (err) {
      // node couldn't execute the command
      console.log('err', err);
      reject(err);
      return false;
    }
    resolve({stdout, stderr});
    console.log(`Succesfully uploaded: 
      stdout: ${stdout}
      stderr: ${stderr}
    `);
  });
});

Don't forget to do the await part in an async function.



来源:https://stackoverflow.com/questions/44085110/upload-pano-image-using-street-view-publish-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!