0

Good people, please help, with this code I am trying to download a * .nwd file, the download happens, but when processing (Translate) it gives an error, I also noticed that SHA1 differs in output when downloading and the file I have. What am I missing?

   <?php
    require_once( "token.php" );
    curl_setopt($curl, CURLOPT_URL, "https://developer.api.autodesk.com/oss/v2/buckets/" . $_REQUEST[ "bucket" ] . "/objects/" . hrtime(1) . "_" . $_FILES[ "file" ][ "name" ]);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
    
    $post = array(
        "file" => new CurlFile( $_FILES[ "file" ][ "tmp_name" ] )
    );
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    
    $headers = array();
    $headers[] = "Authorization: Bearer " . json_decode( $response )->access_token;
    $headers[] = "Content-Length: ". $_FILES["file"]["size"];
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
    $response = curl_exec( $curl );
    
    curl_close( $curl );
    echo $response;
    ?>

token.php for authorization

    <?php
$client = "";
$secret = "";
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "https://developer.api.autodesk.com/authentication/v1/authenticate",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=".$clien."&client_secret=".$secret."&scope=data%3Aread%20data%3Awrite%20data%3Acreate%20bucket%3Aread%20bucket%3Acreate",
      CURLOPT_HTTPHEADER => array(
        "Content-Type: application/x-www-form-urlencoded",
        "Cookie: PF=NBbXr77IMxHIVlUWgWsny9"
      ),
    ));
    
    $response = curl_exec($curl);
    ?>
LyaKich
  • 3
  • 1
  • You mention _downloading_ and _translating_ but in the code snippet I only see one call for retrieving the access token, and another call for uploading the file to Forge. Would you mind sharing the rest of the code as well? Also, for PHP we'd recommend using the official Forge SDKs: https://github.com/Autodesk-Forge/forge-php-client. – Petr Broz Jun 23 '20 at 09:53
  • There is no other code yet. – LyaKich Jun 24 '20 at 11:42
  • Ah ok, in that case I'd definitely recommend using the PHP client I linked to in my previous comment. – Petr Broz Jun 24 '20 at 12:31

0 Answers0