我们正试图通过php中的forge ObjectsApi上传文件。这导致http 504网关始终超时。该文件是800kb,所以这应该不是问题。
这是代码:
$twoLeggedAuth = new Autodesk\Auth\OAuth2\TwoLeggedAuth();
$twoLeggedAuth->setScopes( [ 'data:write' ] );
$twoLeggedAuth->fetchToken();
$apiInstance = new Autodesk\Forge\Client\Api\ObjectsApi( $twoLeggedAuth );
$filename = $inputFileName;
$body = $filename;
$file = new SplFileObject( $body );
$content_length = $file->getSize();
$object_name = $file->getFilename();
try {
$result = $apiInstance->uploadObject( $bucket_key, $object_name, $content_length, $body, null, null );
} catch( Exception $e ) {
echo 'Exception when calling ObjectsApi->uploadObject: ', $e->getMessage(), PHP_EOL;
}
结果是
Exception when calling ObjectsApi->uploadObject: [504] Error connecting to the API (https://developer.api.autodesk.com/oss/v2/buckets/bobbie_pat/objects/test.dwg)
答案 0 :(得分:2)
文档说明代码有问题 https://forge.autodesk.com/blog/basic-usage-forge-sdk-php有一个修复:
但是在uploadObject方法上存在问题,我们将面临错误504.要解决此问题,可以使用更改forge-php-client / lib / ApiClient.php的#196行的解决方法。 p>
//From: curl_setopt( $curl, CURLOPT_POSTFIELDS, $postData ); //To: curl_setopt( $curl, CURLOPT_POSTFIELDS, file_get_contents( $postData ) );
不知道为什么他们不仅修复他们的SDK而不是在他们自己的网站上发布修复。