Streaming assets
Revision as of 08:09, 16 December 2021 by Rudolf@tygron.nl (talk | contribs) (Created page with "{{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...")
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 Geo Share 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 Geo Share asset can be found. $fileName = 'example.tiff'; //Set this: the name of the file to obtain from the Geo Share. $fileToken = 'c0hARlThlohZes2TFuQSZ95pXEtc619t'; //Set this: the access token of the asset on the Geo Share $geoshareUrl = $serverUrl . '/share/' . $domain. '/' . $fileName . '?token=' . $fileToken; streamFromGeoshareToGeotiff( $geoshareUrl, $streamingImportUrl, $fileName );