Streaming assets
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 when your computers has a small memory footprint.
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 );