Current File uploading file size.

Cecil

19+ years progress programming and still learning.
Info:
OS Linux RH SE 4
OE 10.2A02 Enterprise/WebSpeed/Replication.

We have a public website www.ekkoguardian.com which allows our logged in members to upload files to our secure web server. My issue is that my boss now want to show a progression bar of the file being uploaded. AJAX to the rescue.

Currently we allow a maximum of 10MB file upload so there can be a period of time where it looks like nothing is happening for a few minutes.

Is there anyway a second WebSpeed agent can query sibling agent to find out the current size of the file it's currently being uploaded?

I know how to find out what the size of the file that has been uploaded, but by that time it's too late.

Thanks.

I guess PHP will have to be a workaround.
 

redskienz

New Member
I have experienced inserting images to database. What I did is to create chunks of the image with sequence.

e.g:
Let's consider 10mb Image,
I will gave the memptr variable size of 2500kb, assign 2500kb part by part of file and save to database.

Sequence_(ImageChunk)_________Size
1________%$#@^^@^^%&(_________2500kb
2________%$&&^@((@((F_________
2500kb
3________((@#(#&^@#*!_________2500kb
...
..
. and so on

That way, you'll have an idea about the current size of the file being transfer.

Again, this is just an idea. I haven't tested this on web application and not sure if this will work on other file aside from images which i think may work.

good luck.

 

Cecil

19+ years progress programming and still learning.
I think I know the answer. It can't be done with WebSpeed.

Unless Progress comes up with a "Start of WEB-NOTIFY response procedure" event. I can see there is no way of knowing what the size of the file(s) is being received from the messenger.

As they say here in New Zealand "BUGGER".

However I could possibly by pass the "Webspeed Agent" all together and handle the CGI-Messenger responses by writing my own Server Socket programme, but that just to much work.
 
Hey Cecil, as I understood you have written some code to download/upload files through web server to appserver. And I want to ask you an advise.
Let me explain what is my problem.

I am not using webspeed. I use flex + WSA. I already have written upload and download multithreads scripts which can upload any file through WSA to appserver and download file from appserver through WSA to flex client. They work ok and flex even display how many 100kb chuck where transfered by uploading/downloading process.
When download process ended, file stored in memory as Flex Bytearray. User selects directory and saves file to local disk.
At this moment I want to open loaded file (it is report generated by application server).
By security issue flex do not return me full path of file, just saved, and i cannot open it, cause i dont know where is it.

I am looking for alternative method to download file. I think I should use browser to download. I dont want to copy file from application server to webserver. I am looking for smarter way to download file through some web server script. Any advice?

Maxim
 

Cecil

19+ years progress programming and still learning.
The simplest way is to install the OE WebSpeed Messeger on the web server and configure the messenger to do remote connection to the WebSpeed broker via the OpenEdge NameServer or direct connect. The WebSpeed broker will running on the same server as you application server so there would be no need to move the file between the application server and the web server.

Hope this answers your question?

In Summary:


  1. Setup a new WebSpeed Broker on the same server as your WSA.
  2. Install the OpenEdge WebSpeed Messenger on your web server.
  3. Configure the messenger on the web server for remote connection to the WebSpeed Broker.
  4. Write your server side code to handle the web-request for the uploading the file back to the browser.
Check the KB for each step on how to do this.
 
Thanks Cecil, Ill try.
I had a little expirinence with webspeed and know how to setup it.
But never heard about messenger.

Added.
Ahh. It is cgiip.exe/cgiip.sh and it can be resided on different server. Ok, got it.
 

Cecil

19+ years progress programming and still learning.
It's all a bit late now, but here is a HTML5 plus pure JavaScript code to allow a progress bar being displayed on file uploads. Very handy on large files.

Note: As HTML5 is not yet a standard and it does not work correctly in IE or Opera.

Code:
<script language="SpeedScript">

PROCEDURE Output-Headers:

    DEFINE VAR mpUploadedFile AS MEMPTR NO-UNDO. 
    DEFINE VAR chUploadedFileName AS CHAR NO-UNDO. 

    IF REQUEST_METHOD EQ 'POST' THEN
    DO:

            /* 'filename' refers to the name of the field in the form.
            get-binary-data returns the contents of the file associated with the
            form field named 'filename'. */ 
            set-size(mpUploadedFile) = 0.
            ASSIGN mpUploadedFile = get-binary-data("fileToUpload"). 
            IF mpUploadedFile NE ? THEN DO: 
            /* if we got a valid pointer, save data to file. The value of the
            field 'filename' is the file name posted */ 
                ASSIGN chUploadedFileName = get-value("fileToUpload"). 
                COPY-LOB FROM mpUploadedFile TO FILE chUploadedFileName NO-CONVERT. 
            END.
            
            output-content-type("text/html":U).
 
            IF SEARCH(chUploadedFileName) EQ ? THEN
                {&OUT} SUBSTITUTE('File <quote><strong>&1</strong></quote> has <span style="color:red">failed</span> to upload correctly.',
                                  chUploadedFileName).
            ELSE
                {&OUT} SUBSTITUTE('<strong>&1</strong> file has <span style="color:green">successfully</span> been uploaded.',
                                  chUploadedFileName).

            set-size(mpUploadedFile) = 0.
            
    END.

    RETURN.
END PROCEDURE.

IF REQUEST_METHOD EQ 'POST' THEN
    RETURN.

</script>


<!DOCTYPE html>
<html>
<head>
    <title>Upload Files using XMLHttpRequest </title>

    <script type="text/javascript">
      function fileSelected() {
        var file = document.getElementById('fileToUpload').files[0];
        if (file) {
          var fileSize = 0;
          if (file.size > 1024 * 1024)
            fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
          else
            fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';

          document.getElementById('fileName').innerHTML = file.name;
          document.getElementById('fileSize').innerHTML = fileSize;
          document.getElementById('fileType').innerHTML = file.type;
        }
      };

      function uploadFile() {
        var fd = new FormData();
        fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
        var xhr = new XMLHttpRequest();
        xhr.upload.addEventListener("progress", uploadProgress, false);
        xhr.addEventListener("load", uploadComplete, false);
        xhr.addEventListener("error", uploadFailed, false);
        xhr.addEventListener("abort", uploadCanceled, false);
        xhr.open("POST", "`APPURL`/DocumentFileUpload.html");
        xhr.send(fd);
        document.getElementById('webspeedServerResponce').innerHTML = '';
        document.getElementById('progressBar').style.display = '';
      };

      function uploadProgress(evt) {
        if (evt.lengthComputable) {
          var percentComplete = Math.round(evt.loaded * 100 / evt.total);
          document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
          document.getElementById('progressBar').width = percentComplete.toString() + '%';

          if (percentComplete.toString() == '100') {
              document.getElementById('webspeedServerResponce').innerHTML = '`PROVERSION` is processing the file. Please Wait';
          }
          
        }
        else {
          document.getElementById('progressNumber').innerHTML = 'unable to compute';
        }
      };

      function uploadComplete(evt) {
        /* This event is raised when the server send back a response */
        //alert(evt.target.responseText);
        document.getElementById('webspeedServerResponce').innerHTML = evt.target.responseText;
        // Just force it to display 100% to handle smaller files.
        document.getElementById('progressNumber').innerHTML =  '100%';
        document.getElementById('progressBar').width =  '100%';  
        

      };

      function uploadFailed(evt) {
        alert("There was an error attempting to upload the file.");
      };

      function uploadCanceled(evt) {
        alert("The upload has been canceled by the user or the browser dropped the connection.");
      };
    </script>
</head>
<body>

    <style type="text/css">
        label {float:left;
               width:180px;
               text-align:right};
    </style>

  <form id="fileUploadForm" enctype="multipart/form-data" method="post" action="`APPURL`/DocumentFileUpload.html">
    <div style="margin:10px">
      <label for="fileToUpload">Select a File to Upload</label><br />
      <input size="50" type="file" name="fileToUpload" id="fileToUpload" onchange="fileSelected();"/>
    </div>


    <label for="fileName">File Name:</label><div id="fileName">&nbsp;</div>
    <label for="fileSize">File Size:</label><div id="fileSize">&nbsp;</div>
    <label for="fileType">File Type:</label><div id="fileType">&nbsp;</div>


    <div style="margin:10px; clear:both">
      <input type="button" onclick="uploadFile()" value="Upload" />
    </div>

    <label id="progressNumber">0%</label>
      
    <div style="float:left; width:400px;height:24px; border:2px outset #888888; margin:0">
        <table id="progressBar" width="0" style="display:none;margin:0;padding:0">
            <tbody>
                <tr>
                    <td bgcolor="#00CCFF" >&nbsp;</td>
                </tr>   
            </tbody>
        </table>  
    </div>

    <div style="clear:both;margin:10px" id="webspeedServerResponce"></div>
  </form>
</body>
</html>
 
Top