Community
BIM 360 API Forum
Welcome to Autodesk’s BIM 360 API Forums. Share your knowledge, ask questions, and explore popular BIM 360 API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

504 GATEWAY_TIMEOUT when I try to upload file via php

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
1388 Views, 3 Replies

504 GATEWAY_TIMEOUT when I try to upload file via php

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

3 REPLIES 3
Message 2 of 4
mikako_harada
in reply to: Anonymous

(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.  


Mikako Harada
Developer Technical Services
Message 3 of 4
Anonymous
in reply to: Anonymous

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.

 

Message 4 of 4
mikako_harada
in reply to: Anonymous

You can extent the time out limit in the tool you are using. 

 

I'm not php person. But in case of restsharp example:    

 

https://forums.autodesk.com/t5/bim-360-api-forum/bim360field-300s-operation-time-out-error/td-p/7420...

 

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/17481716/how-to-prevent-connection-timeouts-for-large-mysql-impo...

 

https://support.plesk.com/hc/en-us/articles/213918245-Unable-to-upload-database-with-phpMyAdmin-Scri...

 

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


Mikako Harada
Developer Technical Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report