Hello everyone,
I need to integrate the autodesk viewer to view my 3D files on my website.
So I try to make a php script to upload a IFC file. But I have a Gateway timeout error when I try to upload file :
"HTTP/1.1 100 Continue HTTP/1.1 504 GATEWAY_TIMEOUT Content-Length: 0 Connection: keep-alive"
Here my php file :
<?php $current_token= ""; define("bucket_name", "xxx"); define("client_id", "xxx"); define("client_secret","xxx"); define("file_name","test.ifc"); define("access_token","xxx"); $creation_bucket_response=""; $upload_file_response=""; upload_file(); function get_token() { $url = 'https://developer.api.autodesk.com/authentication/v1/authenticate'; $myvars = 'client_id=' . client_id . '&client_secret=' . client_secret . '&grant_type=client_credentials&scope=data:read%20data:write%20bucket:create%20bucket:read'; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded' )); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); $cv = curl_exec( $ch ); return json_decode($cv)->{'access_token'}; } function create_bucket() { $url = 'https://developer.api.autodesk.com/oss/v2/buckets'; $myvars = '{"bucketKey":"'.bucket_name.'","policyKey":"transient"}'; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt( $ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: Bearer '.access_token )); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); echo curl_exec( $ch )."<br/><br/>"; } function upload_file() { $url = 'https://developer.api.autodesk.com/oss/v2/buckets/'.bucket_name.'/objects/'.file_name; echo filesize(file_name)."<br/><br/>"; $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt( $ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Authorization: Bearer '.access_token, 'Content-Length: '.filesize(file_name), 'Content-Type:application/octet-stream', )); curl_setopt( $ch, CURLOPT_POSTFIELDS, array( 'file' => '@' . (file_name) )); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); echo curl_exec( $ch )."<br/><br/>"; } ?>
If I try to upload my test.ifc file via a terminal linux, I've no problem.
I've you got an idea of the problem with php ?
Thanks for your help
(for the sake of others who might be wondering about this case.)
Hi Pierre,
I see you have contacted forge.help@autodesk.com and working with Cyrille.
That's the right channel for Forge API. Please continue discussion with Forge team if you have further question.
Hey Forum,
I'm having the same problem using the PHP SDK with the following code:
$objectDetails = $objectsApi->uploadObject( "bucketName", time().'-'.strtolower(str_replace(' ', '-', $this->modelFile->name)), // filename $this->modelFile->size, $this->modelFile->tempName );
`$objectsApi` is of type `\Autodesk\Forge\Client\Api\ObjectsApi`
https://github.com/Autodesk-Forge/forge-php-client/blob/master/docs/Api/ObjectsApi.md#uploadobject
Getting the following error:
[504] Error connecting to the API (https://developer.api.autodesk.com/oss/v2/buckets/<bucketName>/objects/<objectName>)
Using postman it works great.
You can extent the time out limit in the tool you are using.
I'm not php person. But in case of restsharp example:
When I google with the keywords "php timeout limit", I get discussion like:
http://php.net/manual/en/function.set-time-limit.php
https://stackoverflow.com/questions/30667409/how-to-fix-script-timeout-error-in-phpmyadmin
This type of question is not BIM 360 specific. You can find a lot of help at stackoverflow. (That's the reason why we have moved developer community to stackoverflow.)