getUploadNode Error

Last post 12-04-2007 2:27 PM by bej34. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 11-20-2007 3:14 PM

    • bej34
    • Top 10 Contributor
    • Joined on 11-12-2007
    • Posts 46

    getUploadNode Error

    I have modified the Reference Application: PHP File System Manager upload.php file and the IMFS.php class file as seen below. I keep getting a "Couldn't resolve host 'http:'" error when I run the code. It seems to get stuck on the getUploadNode function. Can someone tell me what I am doing wrong. 

    Page I'm doing the upload on - Test.php 

    <?php
       
        require_once "IMFS.php";
        require_once "Authentication.php";

        $imfs = new IMFS();
        $path = "upload/";
        $file = "D:\Websites\nirvanix\test_c\test.mpg";
        // Get a sessionToken
        $auth = new Authentication();
        $sessionToken = $auth->Login("user", "password", "key");
        echo $sessionToken;
        // Retrieve the upload node with the upload access token.
        // this is passed on to the client so they can authenticate with an IP Address
        // that is different from the servers that was used to login.
        $uploadNode = $imfs->GetUploadNode($sessionToken);
        // retrieve the accessToken
        $accessToken = $uploadNode->GetUploadNode->AccessToken;
        // get server to upload to
        $ipAddress = $uploadNode->GetUploadNode->IPAddress;
        
        $request_uploadfile = "http://$ipaddress/Upload.ashx?uploadToken=$accessToken&destFolderPath=$path";
        $uploadFile = $imfs->postFile($request_uploadfile, $file);
        
        
        
    ?>

    Modified IMFS.php File

    <?php
    /****
    Author:  Nirvanix
    Date:    8-21-2007
    Website: http://developer.nirvanix.com/
    License: See http://developer.nirvanix.com/content/license.aspx
            Limited Permissive License
            This license governs use of the accompanying software. If you use the software,
            you accept this license. If you do not accept the license, do not use or distribute
            the software.
    ****/

    require_once "RestUtils.php";
    require_once "Config.php";

    class IMFS
    {
        //Copies one or more folders to a destination folder
        public function CopyFiles($sessionToken, $srcFilePaths, $destFilePath)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $filePathParams = 'sessionToken=' . $sessionToken . '&';
            $filePathParams = $filePathParams. 'destFolderPath=' . $destFilePath . '&';
           
            // loop through each source file path building the arrray.
            foreach ($srcFilePaths as $filePath)
            {
                $filePathParams = $filePathParams . 'srcFilePath=' . $filePath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/copyfiles.ashx?' . $filePathParams);
           
            if ($DEBUG)
            {
                print '<!--CopyFiles: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }
       
        //Copies one or more folders to a destination folder
        public function CopyFolders($sessionToken, $srcFolderPaths, $destFolderPath)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // set the parameters.
            $folderPathParams = 'sessionToken=' . $sessionToken . '&';
            $folderPathParams = $folderPathParams . 'destFolderPath=' . $destFolderPath . '&';

            // loop through each source file path building the arrray.
            foreach ($srcFolderPaths as $folderPath)
            {
                $folderPathParams = $folderPathParams . 'srcFolderPath=' . $folderPath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/copyfolders.ashx?' . $folderPathParams);
           
            if ($DEBUG)
            {
                print '<!--CopyFolders: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

        // Creates one or more folders
        public function CreateFolders($sessionToken, $folderPaths)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $folderPathParams = 'sessionToken=' . $sessionToken . '&';

            // loop through each source file path building the arrray.
            foreach ($folderPaths as $folderPath)
            {
                $folderPathParams = $folderPathParams . 'folderPath=' . $folderPath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/createfolders.ashx?' . $folderPathParams);
           
            if ($DEBUG)
            {
                print '<!--CreateFolders: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml; 
        }

        //Deletes one or more files
        public function DeleteFiles($sessionToken, $filePaths)
        {
            global $DEBUG;
            global $IMFSHOST;
           

            // Set the parameters
            $params = 'sessionToken=' . $sessionToken . '&';

            // loop through each source file path building the arrray.
            foreach ($filePaths as $filePath)
            {
                $params = $params . 'filePath=' . $filePath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/deletefiles.ashx?' . $params);
           
            if ($DEBUG)
            {
                print '<!--DeleteFiles: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;       
        }

        //Deletes one or more folders
        public function DeleteFolders($sessionToken, $folderPaths)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $folderPathParams = 'sessionToken=' . $sessionToken . '&';

            // loop through each source file path building the arrray.
            foreach ($folderPaths as $folderPath)
            {
                $folderPathParams = $folderPathParams . 'folderPath=' . $folderPath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/deletefolders.ashx?' . $folderPathParams);
           
            if ($DEBUG)
            {
                print '<!--DeleteFolders: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;       
        }

        // Gets the links for an array of files.
        public function GetDownloadLinks($sessionToken, $filePaths, $expiration, $restrictedIP = null)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $filePathParams = 'sessionToken=' . $sessionToken . '&';
            $filePathParams = $filePathParams . 'expiration=' . $expiration . '&';
            $filePathParams = $filePathParams . 'restrictedIP=' . $restrictedIP . '&';

            // loop through each source file path building the arrray.
            foreach ($filePaths as $filePath)
            {
                $filePathParams = $filePathParams . 'filePath=' . $filePath . '&';           
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/GetDownloadLinks.ashx?' . $filePathParams);
           
            if ($DEBUG)
            {
                print '<!--GetDownloadLinks: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

        // Get the node to upload this file to.
        // Since this is over the web we have to estimate the sizeBytes since we cannot control
        // the client.
        public function GetUploadNode($sessionToken)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $params = 'sessionToken=' . $sessionToken . '&';
            $params = $params . 'sizeBytes=10000';

            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/GetUploadNode.ashx?' . $params);

            if ($DEBUG)
            {
                print '<!--GetUploadNode: ';
                print_r($xmlstring);
                print '-->';           
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

        // Lists the specified folder.
        public function ListFolder($sessionToken, $folderPath, $pageNumber, $pageSize, $sortCode, $sortDescending)
        {
            global $DEBUG;
            global $IMFSHOST;
           

            // Set the parameters
            $params = 'sessionToken=' . $sessionToken . '&';
            $params = $params . 'folderPath=' . $folderPath . '&';
            $params = $params . 'pageNumber=' . $pageNumber . '&';
            $params = $params . 'pageSize=' . $pageSize . '&';
            $params = $params . 'sortCode=' . $sortCode . '&';
            $params = $params . 'sortDescending=' . $sortDescending;

            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/listfolder.ashx?' . $params);
           
            if ($DEBUG)
            {
                print '<!--ListFolder: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

        //Moves one or more files to a destination folder
        public function MoveFiles($sessionToken, $srcFilePaths, $destFolderPath)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $params = 'sessionToken=' . $sessionToken . '&';
            $params = $params . 'destFolderPath=' . $destFolderPath . '&';

            // loop through each source file path building the arrray.
            foreach ($srcFilePaths as $filePath)
            {
                $params = $params . 'srcFilePath=' . $filePath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/movefiles.ashx?' . $params);
           
            if ($DEBUG)
            {
                print '<!--MoveFiles: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }
       
        // Moves one or more folders to a destination folder
        public function MoveFolders($sessionToken, $srcFolderPaths, $destFolderPath)
        {
            global $DEBUG;
            global $IMFSHOST;
           

            // Set the parameters
            $folderPathParams = 'sessionToken=' . $sessionToken . '&';
            $folderPathParams = $folderPathParams . 'destFolderPath=' . $destFolderPath . '&';

            // loop through each source file path building the arrray.
            foreach ($srcFolderPaths as $folderPath)
            {
                $folderPathParams = $folderPathParams . 'srcFolderPath=' . $folderPath . '&';
            }
           
            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/movefolders.ashx?' . $folderPathParams);
           
            if ($DEBUG)
            {
                print '<!--MoveFolders: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

        // Renames a single file
        public function RenameFile($sessionToken, $filePath, $newFileName)
        {
            global $DEBUG;
            global $IMFSHOST;
           

            // Set the parameters
            $params = 'sessionToken=' . $sessionToken . '&';
            $params = $params . 'filePath=' . $filePath . '&';
            $params = $params . 'newFileName=' . $newFileName;

            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/renamefile.ashx?' . $params);
           
            if ($DEBUG)
            {
                print '<!--RenameFile: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

        // Renames a single folder
        public function RenameFolder($sessionToken, $folderPath, $newFolderName)
        {
            global $DEBUG;
            global $IMFSHOST;

            // Set the parameters
            $folderPathParams = 'sessionToken=' . $sessionToken . '&';
            $folderPathParams = $folderPathParams . 'folderPath=' . $folderPath . '&';
            $folderPathParams = $folderPathParams . 'newFolderName=' . $newFolderName;

            // retrieve from the REST interface the response xml.
            $xmlstring = curlGet($IMFSHOST . '/ws/IMFS/renamefolder.ashx?' . $folderPathParams);
           
            if ($DEBUG)
            {
                print '<!--RenameFolder: ';
                print_r($xmlstring);
                print '-->';
            }
           
            // turn into an object for easier handling.
            $xml = new SimpleXMLElement($xmlstring);
           
            return $xml;
        }

    // Curl method to post a file.
    function postFile($restlink, $file, $timeout = 20) {
        $crl = curl_init();
        if ( !$crl ) return NULL;

        // Set the other parameters on the $restlink to simplify this example.
        // somefile can be any value that does not conflict with an existing parameter,
        // the @$file tells curl to open the file at $file (must be a full path) and stream
        // it to the recipient.
        $postfields = array(
            'somefile'=>"@$file"      
        );
       
        // Set options
        curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($crl, CURLOPT_URL, $restlink);
        curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($crl, CURLOPT_POST, 1);
        curl_setopt($crl, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($crl, CURLOPT_POSTFIELDS, $postfields);
        curl_setopt($crl, CURLOPT_VERBOSE, 1);

        // excute curl request
        $result = curl_exec($crl);
       
        // If there was an error print the result.
        if (curl_errno($crl)) {
            print curl_error($crl);
        }
       
        // Close the curl library
        curl_close ($crl);

        return $result;
    }
    function transcodeVideo($restlink, $timeout = 20) {
        $crl = curl_init();
        if ( !$crl ) return NULL;

        // Set the other parameters on the $restlink to simplify this example.
        // somefile can be any value that does not conflict with an existing parameter,
        // the @$file tells curl to open the file at $file (must be a full path) and stream
        // it to the recipient.
       
        // Set options
        curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($crl, CURLOPT_URL, $restlink);
        curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($crl, CURLOPT_POST, 1);
        curl_setopt($crl, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($crl, CURLOPT_VERBOSE, 1);

        // excute curl request
        $result = curl_exec($crl);
       
        // If there was an error print the result.
        if (curl_errno($crl)) {
            print curl_error($crl);
        }
       
        // Close the curl library
        curl_close ($crl);

        return $result;
    }
    }
    ?>

    http://www.brianjinwright.com
    Filed under: , ,
  • 11-20-2007 4:00 PM In reply to

    • bej34
    • Top 10 Contributor
    • Joined on 11-12-2007
    • Posts 46

    Re: getUploadNode Error

    Also when I try to create a folder using the createFolders function I get an error on the for each statement. 

    http://www.brianjinwright.com
  • 11-20-2007 4:54 PM In reply to

    • bej34
    • Top 10 Contributor
    • Joined on 11-12-2007
    • Posts 46

    Re: getUploadNode Error

     Sorry about the post above. It was the "a" in the $ipAddress variable in the request link variable in the test.php page. Also the video transcode function works well to.

    http://www.brianjinwright.com
  • 12-04-2007 7:18 AM In reply to

    • BarryR
    • Top 10 Contributor
    • Joined on 07-20-2007
    • San Diego
    • Posts 602

    Re: getUploadNode Error

     Just to make sure you are going ok, can I consider this issue taken care of?

    Regards,
        Barry R.
     

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
  • 12-04-2007 2:27 PM In reply to

    • bej34
    • Top 10 Contributor
    • Joined on 11-12-2007
    • Posts 46

    Re: getUploadNode Error

    Yes you can

    http://www.brianjinwright.com
Page 1 of 1 (5 items)