Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 637
Product
XFile
Title
Best Practice: Obtaining and Displaying the server response from an upload request
Problem

XFile does not automatically display the server response from an upload request. It must be explicitly retrieved from XFile's Response property. This may initially be confusing, as the browser typically displays the response automatically. When using XFile in a web page, XFile, not the browser, gets the server response, and the developer must make the decision as to how the response will be handled. This article will explain the different ways to retrieve information about the server response.

Solution
Displaying the Server Response in the Browser

In order to display the server response from your upload request, you must use XFile's Response property. The Response property is a property of the XFRequest object, XFile's file transfer engine. Since the server response may include server errors, displaying the response will be helpful for troubleshooting in the beginning stages of your XFile development, even if you choose not to display the server response in the final version of your application.

The Response property is always accessed through the XFRequest object, regardless of whether you are scripting against the XFRequest object alone for a non-visual upload, or if you are using the visual control for file selection (the AXFFile object). When using the AXFFile object, you need to remember to drill down to the XFRequest object before calling the Response property. The following demonstrates how to get to the Response property with either control:

Without the visual control:

<!--Instantiate the non-visual file transfer engine,
    which is the XFRequest object alone-->

<OBJECT CLASSID="CLSID:C3A57B60-C117-11D2-BD9B-00105A0A7E89"
   codebase="/SAXFileSamples/saxfile.cab" ID="SAXFile" VIEWASTEXT>
</OBJECT>

<SCRIPT>

   ... [other code related to transferring the files]

   Dim myVar
   '---Access the server response with the Response property
   myVar = SAXFile.Response
</SCRIPT>

With the visual control:

<!--Instantiate the visual (GUI) control,
    which includes the file transfer engine (XFRequest object)-->

<OBJECT classid="CLSID:230C3D02-DA27-11D2-8612-00A0C93EEA3C"
   codebase="/SAXFileSamples/saxfile.cab" height="200"
   ID="AXFFile" style="HEIGHT: 200px; LEFT: 0px; TOP: 0px;
   WIDTH: 400px" width="400" VIEWASTEXT>
   ...[other code related to parameters]
</OBJECT>

<SCRIPT>

   ...[other code related to transferring the files]

   Dim myVar
   '---Access the server response by drilling down to the XFRequest object
   '---to the Response property
   myVar = AXFFile.XFRequest.Response
</SCRIPT>

Below follows a complete example of the client-side code neccessary to obtain the server response and write it out the original page that made the request. This example uses the XFRequest object to upload a predetermined file for the user, and writes the server response back to the <SPAN> tag on the same page.

  • In the HTML, a <SPAN> tag is given the "ID" attribute value of "ResponseText".
  • In the script, this <SPAN> tag is referenced via HTML DOM and it's "InnerHTML" property is populated with value of the server response using the Response property.
  • The HTML returned by the page "formresp.asp" will be written to the <SPAN> section of the original HTML document. If there is a server-side error, that error page will be returned instead. This can be tested by deliberately forcing an error in your server-side processing script.

<HTML>
<BODY>
   <SCRIPT LANGUAGE="VBS">

   Sub UploadButton_onClick()

   '-- Set the URL to the page that will process the upload server-side
    SAXFile.CurrentURL = "http://MyServer/MyApplication/formresp.asp"

   ' -- add the file to be uploaded
    SAXFile.AddFile "C:\boot.ini", "FileName1"

   ' -- start the transfer
    SAXFile.Start

   ' -- write the contents of the response to the "ResponseText" span tag.
    ResponseText.InnerHTML = SAXFile.Response

   ' -- after the transfer, disable the upload button
    document.all("UploadButton").disabled = true


   End Sub

   </SCRIPT>

   Press "Upload!" to upload "C:\boot.ini" and retrieve
   a response from the server.

   <INPUT Type="Button" Name="UploadButton" value="Upload!">

<!-- The Response will populate in the span tag below. -->
<SPAN ID="ResponseText"></SPAN>

<OBJECT CLASSID="clsid:C3A57B60-C117-11D2-BD9B-00105A0A7E89"
   codebase="/SAXFileSamples/saxfile.cab" ID="SAXFile" VIEWASTEXT>
</OBJECT>

</BODY>
</HTML>

The complete scripts for this example are provided as an attachment to this article. Additionally, scripts are provided that show how to do the same thing using the AXFFile object and the Progress Indicator (the AXFFileProgress object).

Sending the Response to a File

To send the server response to a file on the client, instead of to the browser, use the ResponseFile property (http://support.softartisans.com/docs/XFile/prog_ref_xfrequest_responsefile.htm) of the XFRequest object instead of the Response property.

This property cannot be used in conjunction with the Response property. Either the Response property or the ResponseFile property should be used in your script, but not both.

This property needs to be set before calling the start method of the XFRequest object. In the context of the above example, the <SPAN> would be unnecessary, and the code could be changed as follows:

   SAXFile.AddFile "C:\boot.ini", "FileName1"
   SAXFile.ResponseFile = "C:\MyFile.txt"
   SAXFile.Start
   document.all("UploadButton").disabled = true

Retrieving Only Part of the Server Response

You are not limited to dealing with the entire contents of the server response. Specific parts of the response that can be referenced separately include:

Property NameProperty Description
ResponseStatus The server response code.
ReponseHeaders The collection of response headers.
ResponseSize The size of the response in bytes.

The Attached Samples

The attached samples provide both the client-side and server side code necessary for displaying the server response after an upload. Note that in this second sample, the server response is obtained on the Progress Indicator page and then sent back to the <SPAN> tag on the XFile page.

Using the Non-visual File Transfer Engine: A 2-Page Sample

File: KB637_NonVisual_NoPrgInd.zip
Client Script: saxfile_onefile.htm
Server Script: formresp.asp

Using the Graphical File Selector Control and a Client-Side Progress Indicator: A 3-Page Sample

File: KB637_Visual_wProgressIndicator.zip
Client Script (Xfile Page): AXFFile.htm
Client Script (Progress Indicator Page): AXFFileProgress.htm
Server Script: formresp.asp

Attachments
Attachments/KB637_Visual_wProgressIndicator.zip
Attachments/KB637_NonVisual_NoPrgrInd.zip
Created : 1/6/2004 11:33:16 AM (last modified : 1/6/2004 11:33:16 AM)
Rate this article!
Comments