/**
  * Streams the object based on its details
  * 
  * @see external-content/seamist/SeaMistRepository#streamObject()
  */
 public function streamObject(SeaMistObject $object, $toFile = null)
 {
     // TODO: Not implementing until local caching of content files is possible, as otherwise
     // we need to copy file locally first, THEN forward it to the user's browser.
     // not going to bother with that just yet.
     $contentUrl = $object->getContentUrl();
     $contentType = strlen($object->contentStreamMimeType) ? $object->contentStreamMimeType : 'application/octet-stream';
     // Allow the URL for streaming content to be modified by any child impl
     $contentUrl = $this->modifyStreamUrl($contentUrl);
     //  "?alf_ticket=$this->ticket";
     $session = curl_init($contentUrl);
     if (!strlen($toFile)) {
         // QUICK HACK
         $n = $object->name;
         $filename = rawurlencode($n);
         header("Content-Disposition: atachment; filename={$filename}");
         header("Content-Type: {$contentType}");
         // header("Content-Length: ".filesize("$path/$filename"));
         header("Pragma: no-cache");
         header("Expires: 0");
         curl_exec($session);
     } else {
         // get the file and store it into a local item
         curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($session);
         $fp = fopen($toFile, 'w');
         if (!$fp) {
             throw new Exception("Could not write file to {$toFile}");
         }
         fwrite($fp, $response);
         fclose($fp);
     }
     curl_close($session);
 }