Streaming assets: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 6: | Line 6: | ||
===PHP=== | ===PHP=== | ||
This example is a functional PHP example for streaming a [[GeoTIFF]] asset on the [[ | This example is a functional PHP example for streaming a [[GeoTIFF]] asset on the [[GeoShare]] directly to a session. | ||
{{code|1= | {{code|1= | ||
| Line 46: | Line 46: | ||
$streamingImportUrl = $serverUrl . '/api/session/stream/import?token=' . $apiToken; | $streamingImportUrl = $serverUrl . '/api/session/stream/import?token=' . $apiToken; | ||
$domain = 'tygron'; //Set this: the domain in which the desired | $domain = 'tygron'; //Set this: the domain in which the desired GeoShare asset can be found. | ||
$fileName = 'example.tiff'; //Set this: the name of the file to obtain from the | $fileName = 'example.tiff'; //Set this: the name of the file to obtain from the GeoShare. | ||
$fileToken = 'c0hARlThlohZes2TFuQSZ95pXEtc619t'; //Set this: the access token of the asset on the | $fileToken = 'c0hARlThlohZes2TFuQSZ95pXEtc619t'; //Set this: the access token of the asset on the GeoShare | ||
$geoshareUrl = $serverUrl . '/share/' . $domain. '/' . $fileName . '?token=' . $fileToken; | $geoshareUrl = $serverUrl . '/share/' . $domain. '/' . $fileName . '?token=' . $fileToken; | ||
Revision as of 07:29, 2 July 2026
This article is a stub.
The streaming endpoint of the API allows the download and upload of large assets which are infeasible to download and upload in full. This is especially important in environments where there isn't a large allowance of memory.
Examples
PHP
This example is a functional PHP example for streaming a GeoTIFF asset on the GeoShare directly to a session.
function streamFromGeoshareToGeotiff( string $geoshareableUrl, string $streamingImportUrl, string $fileName, int $geotiffId = null ) {
$targetUrl = $streamingImportUrl . '&name=' . $fileName . '&mapLink=GEO_TIFFS';
if ( !is_null($geotiffId) ) {
$targetUrl .='&id='.$geotiffId;
}
//Reading a file can be done via a simple resource handle.
$originHandle = fopen( $geoshareableUrl, 'r' );
//Writing should be done as a proper webcall. Curl will handle the low-level stuff.
$ch = curl_init();
curl_setopt( $ch, CURLOPT_PUT, 1 ); //Required for infile to work properly
curl_setopt( $ch, CURLOPT_INFILE, ( $originHandle ) );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); //Overwrite method (back) to POST
curl_setopt( $ch, CURLOPT_URL, $targetUrl );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec($ch);
$curlError = curl_error($ch);
$statusCode = curl_getinfo ( $ch ,CURLINFO_HTTP_CODE );
curl_close($ch);
fclose($originHandle);
return [
'result' => $result,
'statusCode' => $statusCode,
'curlError' => $curlError
];
}
$serverUrl = 'https://engine.tygron.com'; //Set this: the url of the server.
$apiToken = 'c0hARlThlohZes2TFuQSZ95pXEtc619t'; //Set this: API token of the session.
$streamingImportUrl = $serverUrl . '/api/session/stream/import?token=' . $apiToken;
$domain = 'tygron'; //Set this: the domain in which the desired GeoShare asset can be found.
$fileName = 'example.tiff'; //Set this: the name of the file to obtain from the GeoShare.
$fileToken = 'c0hARlThlohZes2TFuQSZ95pXEtc619t'; //Set this: the access token of the asset on the GeoShare
$geoshareUrl = $serverUrl . '/share/' . $domain. '/' . $fileName . '?token=' . $fileToken;
streamFromGeoshareToGeotiff( $geoshareUrl, $streamingImportUrl, $fileName );