File Overwrite

Last post 06-17-2008 2:40 PM by PhilP. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 06-09-2008 6:54 PM

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    File Overwrite

     My users are having difficulty with the inability to overwrite existing files.  When do you think this issue will be fixed?

     

    Thanks,

    Phil 

  • 06-09-2008 7:14 PM In reply to

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

    Re: File Overwrite

     You can overwite existing files by calling GetStorageNodeExtended and passing true to the fileOverwite parameter.  You can find more detail about this call here:

    http://developer.nirvanix.com/sitefiles/1000/API.html#_TocGetStorageNodeExtended

    Regards,
        Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
    Filed under: ,
  • 06-09-2008 7:45 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

     I wanted to implement this in the FTP Proxy, but I don't see it called anywhere in the source code.  Could you suggest where this function call should be placed?

     

    Thanks,

    Phil 

  • 06-09-2008 8:11 PM In reply to

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

    Re: File Overwrite

     The FTP Proxy uses the deprecated GetUploadNode, You can replace that method directly and the output should be identical.

    Regards,
       Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
  • 06-09-2008 9:20 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

     I've found the references to GetUploadNode in the ..\Web References\NVXIMFS\IMFS.wsdl and Reference.cs files of the FTP Proxy code, but I am not sure what exactly to replace.  I cannot find documentation to the GetUploadNode function and I'm new to C# so I'm a bit lost at where to replace calls to GetStorageNodeExtended and to  allow overwriting a file.  Could you give me a bit more help on this?

    Thanks,

    Phil 

  • 06-09-2008 11:26 PM In reply to

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

    Re: File Overwrite

     I just checked the code itself and it was using GetStorageNode, below are the steps to replace this call with the extended version that lets you overwrite..  Since it has been quite some time since this application has been released you should update the web reference for IMFS.  To do this you will need to right click on the NVXIMFS web reference and click "Update Reference" as seen below:

     

    Once this is updated you will be able to see in the IMFS object the new method calls.  Open to the file FTPServerControl.cs from the solution explorer and browse to the UploadFile method on line 615. 

    Update the code from:

                // Get the storage node and update the transfer URL.
                StorageNode storageNode = imfs.GetStorageNode(clientAuthenticationToken.SessionToken, 10000, null);

    to:


                // Get the storage node and update the transfer URL.
                StorageNode storageNode = imfs.GetStorageNodeExtended(clientAuthenticationToken.SessionToken,
                    10000, clientIP, false, currentDirectory, true, 600, 259200);


    This will let you overwrite (assuming the FTP Protocol allows it which I'm not sure of) and it will also use the clients IP Address to decide which node to upload to.

     Optionally something that needs to be updated as well is:

    Original (FTPServerControl.cs line 372):

                    SearchResults results = imfs.SearchFileSystem(clientAuthenticationToken.SessionToken, clientAuthenticationToken.Username,
                        filename, null, 0, 0, DateTime.Parse("1/1/1900"), DateTime.Parse("1/1/3000"), 1000);               
                    foreach (SearchItem item in results.Item)
                    {
                        if (srcFile[0] == '/')
                            srcFile = srcFile.Substring(1);
                        if (item.ItemPath == srcFile)
                        {
                            return item.CreatedDate;
                        }
                    }
                    return DateTime.MinValue;

    To:

                    PathInfo pathInfo = imfs.GetPathInfo(clientAuthenticationToken.SessionToken, currentDirectory + "/" + filename, false, false, false);
                    return pathInfo.CreatedDate;

    The second fix will improve the speed of downloads / file lookups and avoid a search charge.

    Best regards,
         Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
  • 06-10-2008 7:14 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

    Thanks for the detailed instructions.   I have not found the second fix you mentioned that improves speed and lookups.  I searched the FTPServerControl.cs file as well as the other files and couldn't find that code segment.

     I also need to update the Nirvanix Client Application to allow overwrites - I'm assuming it is the same fix, is that correct?

    Thanks,

    Phil
     

  • 06-11-2008 11:43 PM In reply to

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

    Re: File Overwrite

     Yes the same fix could be applied.  I haven't verified if there is any secondary validation logic on the client that would prevent this.

    Regards,
        Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
  • 06-16-2008 6:52 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

     Barry - could you help me out with the details on changing file overwriting in the browser-based php file application?

    It allows uploading of files of the same name without a warning, but doesn't actually overwrite the file.  There is no error message either.  I want the uploaded file to overwrite the existing file so I expect I need to use GetStorageNodeExtended.  You had mentioned the GetUploadNode function as what would need replaced.  I found reference to it in the upload.php file and the NirvanixAPI/IMFS.php files.  Here are the code snippets - what would need changed here?

    Thanks,
    Phil

     From upload.php

         // 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;

     From IMFS.php

        // 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;
        }
     

  • 06-16-2008 7:08 PM In reply to

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

    Re: File Overwrite

    You can change the code to:

    Upload.php:

      $imfs->GetStorageNodeExtended($sessionToken, $path);


    IMFS:

        // 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 GetStorageNodeExtended($sessionToken, $destFolderPath)
        {
            global $DEBUG;
            global $IMFSHOST;
           
            // Set the parameters
            $params = 'sessionToken=' . $sessionToken . '&';
            $params .= 'destFolderPath=' . $destFolderPath . '&';
            $params .= 'ipRestricted=false&';
            $params .= 'fileOverwrite=true&';
            $params .= 'sizeBytes=10000';

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

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

    I haven't tested the code but it should be close enough for you to get going.  Let me know if you have any issues with the code above.

    Regards,
        Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
  • 06-16-2008 8:02 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

    I ran into a problem in the upload.php file.  I replaced all 3 references to GetUploadNode with GetStorageNodeExtended, which fixed an initial problem but now there is a problem with the $ipAddress variable, I think, because the page hangs with a browser error "can't find http://upload.ashx/" which looks like the ip address isn't getting passed.  Is that a parameter returned by GetStorageNodeExtended?  Any ideas?

     Thanks,

    Phil

     // 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->GetStorageNodeExtended($sessionToken, $path);
        // retrieve the accessToken
        $accessToken = $uploadNode->GetStorageNodeExtended->AccessToken;
        // get server to upload to
        $ipAddress = $uploadNode->GetStorageNodeExtended->IPAddress;
    ?>
    <div class="container">
                <h4>Upload File to: <?php echo htmlspecialchars($path); ?></h4>
                <form ENCTYPE="multipart/form-data" action="http://<?php print $ipAddress; ?>/Upload.ashx" method="post">
                    <input type="hidden" name="uploadToken" value="<?php print $accessToken; ?>"/>
                    <input type="hidden" name="destFolderPath" value="<?php print $path ?>"/>
                    <input type="hidden" name="forwardingUrl" value="http://<?php print $_SERVER['SERVER_NAME']; ?>/browse.php?path=<?php print $path; ?>"/>
                    <LABEL for="uploadFile1">File: </LABEL>
                    <input type="file" name="uploadFile"/><br>
                    <input type="submit" value="Upload"/><input type="button" value="Cancel" onClick="BLOCKED SCRIPThistory.back();" />
                </form>
                </div>

     

  • 06-16-2008 8:13 PM In reply to

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

    Re: File Overwrite

     You should do:

    $uploadNode = $imfs->GetStorageNodeExtended($sessionToken, $path);

    print_r($uploadNode);

    to view the contents of the returned data.  The new method returns:

     

               <xs:element name="ResponseCode" type="xs:integer" />
    <xs:element name="ErrorMessage" minOccurs="0" type="xs:string" />
    <xs:element name="UploadHost" maxOccurs="unbounded " />
    <xs:element name="UploadToken" maxOccurs="unbounded " />
    Meaning you shoudl replace the IP Address call with UploadHost and accessToken with UploadToken.
    Regards,
    Barry R.
    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
  • 06-16-2008 10:04 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

    Thanks - I looked at the documentation and realized that I needed to add UploadHost & UploadToken.  I also used the print_r() check the values and they are correct, but for some reason it appears the variable $ipAddress is not getting the UploadHost info.  Any suggestions?

    Thanks,

    Phil
     

  • 06-16-2008 11:56 PM In reply to

    • PhilP
    • Top 25 Contributor
    • Joined on 02-28-2008
    • Posts 14

    Re: File Overwrite

    I'm not a php expert so I'm sure this is a simple fix, but switching from GetUploadNode to GetStorageNodeExtended is causing a problem passing the UploadToken and UploadHost.  I've used print_r & echo commands to step through the code and when I switch functions the $accessToken and $ipAddress do not get populated with values.  Is there a different syntax that should be used from the current:

    $accessToken = $uploadNode->GetStorageNodeExtended->UploadToken;
    $ipAddress = $uploadNode->GetStorageNodeExtended->UploadHost;

     

    Thanks,

    Phil 

  • 06-17-2008 3:47 AM In reply to

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

    Re: File Overwrite

     I would like to see the output from the print_r statement since that will contain the node structure that we need to traverse to get to the specific nodes you are looking for.

    Thanks,
       Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@msn.com
    Gmail: barryruffner@gmail.com
Page 1 of 2 (18 items) 1 2 Next >