简体   繁体   中英

Autodesk-forge translation failed for rvt file

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 );

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM