0

I have one rvt file which is works fine with oss manager application, upload and translation work fine. but I upload same file through CURL call, file uploaded successful and I can see its listed in OSS manager app, but translation failed there. Seems like file is getting corrupt in uploading.

CURL call for file upload in PHP:

$headers = array
(
'Content-Type: application/octet-stream',
'Authorization: Bearer '.$access_token,
);

$post = array(
        "file" => new CurlFile( 'manual.rvt' )
);
    
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://developer.api.autodesk.com/oss/v2/buckets/testriz/objects/manual.rvt' );
//curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch );
curl_close( $ch );

1 Answers1

0

The CurlFile and $post array will cause the wrong content-type and file size. Please use file_get_contents instead. Here is my revision:

<?php
    $access_token = '';
    $headers = array
    (
        'Content-Type: application/octet-stream',
        'Authorization: Bearer '.$access_token,
    );

    $file_realpath = './manual.rvt';
        
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, 'https://developer.api.autodesk.com/oss/v2/buckets/testriz/objects/manual.rvt' );
    //curl_setopt( $ch,CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, file_get_contents( $file_realpath ) );
    $result = curl_exec( $ch );

    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    print_r($http_status);
    print_r($result);

    curl_close( $ch );
?>

ref: Curl PHP PUT request changes file content

Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • Hi Eason, thank you for the answer, it resolved the issue, now I am uploading a larger file through resumable endpoint, but its giving 100 error code on last chunk upload. Any idea? – Rizwan Karim May 25 '21 at 15:46
  • @RizwanKarim there is no error code 100 according to our [API doc](https://forge.autodesk.com/en/docs/data/v2/reference/http/buckets-:bucketKey-objects-:objectName-resumable-PUT/#http-status-code-summary). Could you share more details? – Eason Kang May 26 '21 at 04:17