Abnormal behavior JsFunc_FileStateChanged

Feb 3, 2009 at 10:56 PM
For show the problem, I wrote this code.

default.aspx
...
        <asp:Label ID="Label1" runat="server" Text="File list on a server..."></asp:Label><br />
        <asp:Label ID="labelFileList" runat="server" Text=""></asp:Label><br /><br />
        <asp:Label ID="Label2" runat="server" Text="Load a new file..."></asp:Label>
    <script type="text/javascript">
            function FileStateChanged(uploader, file, httpStatus, isLast){
                       Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
                       if(file.state > Flajaxian.File_Uploading && isLast){
                         document.location.href = "Default.aspx"
                         }
                       }
    </script>
<fjx:FileUploader ID="FileUploader1" JsFunc_FileStateChanged="FileStateChanged" runat="server" >
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" />
    </Adapters>
</fjx:FileUploader>
...

and

default.aspx.vb
...
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        labelFileList.Text = ""
        Dim fileName, solonome As String
        Dim fileEntries As String() = IO.Directory.GetFiles(Application.Contents("absolutePathUpload"))
        For Each fileName In fileEntries
            solonome = fileName.Remove(0, Len(Application("absolutePathUpload")))
            labelFileList.Text = labelFileList.Text + solonome + "<br/>"
        Next fileName

    End Sub
...

The application work fine, and all files uploaded is putting  in the UploadFolder; practically, finished the file upload, function FileStateChanged reload default.aspx and the page show all the files put in the upload directory, but:
-Randomly, the last files put is not show in list.
-If reload page the last files appears.
-It seems to me that this happens more frequently with large files.

I believe that JsFunc_FileStateChanged firing when the transfer ends, but does not seem so.

I think the real question is: how do I run the code when the file is actually stored in the destination folder?


Thanks for the valuable support, any help is appreciated
Really thanks
Coordinator
Feb 4, 2009 at 12:39 AM
Most probably this is a timing issue. FileStateChanged function detects when the last byte of the file was sent from the client but it takes some time for the server to turn the stream into file system file, and for the larger files this time is bigger. So you need a little delay to adjast for that. Something like:

function FileStateChanged(uploader, file, httpStatus, isLast){
           Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
           if(file.state > Flajaxian.File_Uploading && isLast){
                        var CRITICAL_SIZE = ??
                        var wait = file.bytes > CRITICAL_SIZE ? 500 : 50;
                         setTimeout(function(){ document.location.href = "Default.aspx"; }, wait);
            }
}


You can adjast the CRITICAL_SIZE and the wait time depending on your server.
Feb 4, 2009 at 11:17 AM
Thank you for suggestion. I tried, but in environments multihosting is very difficult to establish value for "CRITICAL_SIZE". In some cases, 15 seconds were not enough, and excessively penalizing each upload does not seem to me a optimal solution.

For resolve the problem, I tried also to use instead of Sub Page.Load, the following code:

"
    Protected Sub FileUploader_FileReceived(ByVal sender As Object, ByVal e As com.flajaxian.FileReceivedEventArgs)
        labelFileList.Text = ""
        Dim fileName, solonome As String
        Dim fileEntries As String() = IO.Directory.GetFiles(Application.Contents("absolutePathUpload"))
        For Each fileName In fileEntries
            solonome = fileName.Remove(0, Len(Application("absolutePathUpload")))
            labelFileList.Text = labelFileList.Text + solonome + "<br/>"
        Next fileName
    End Sub
"
But does not back the updated value of "labelFileList".

    
I tried also the following code
"
    Protected Sub FileUploader_FileReceived(ByVal sender As Object, ByVal e As com.flajaxian.FileReceivedEventArgs)
        Response.Redirect("AnotherPage.aspx")
    End Sub
"
But does not go to!

Some other idea to intercept the moment where the file is permanently stored on the file system?

I apologize for the trouble and insistently, in truth the answer to this question allows me to create a system driven by server, and based on what is actually uploaded.

Thank you for your time
Coordinator
Feb 4, 2009 at 3:54 PM
If you are talking about 15 seconds it must be an issue of file synchronization between different servers in your farm and has nothing to do with the control. 

Ask the question to the producer of the service reponsible for server file synchronization of the servers in your farm.
Feb 4, 2009 at 4:35 PM
Sorry, but the same problem have in my local server, after setting 5 second for  "CRITICAL_SIZE". Is not problem of synchronization between different servers.

Behavior of "Sub FileUploader_FileReceived", wrote on my previous post, is normal?
Nov 19, 2012 at 8:33 PM

Hello

I need help. Everything works correctly, but do not load all images on the database. It's like some pictures still not been saved. Please help me as I read four pages of help and I can not fix it.

function FileStateChanged(uploader, file, httpStatus, isLast) {    if (isLast == true && file.state > Flajaxian.File_Uploading) {        //alert('filestate:' + file.state);        //alert('httpStatus:' + httpStatus);        if (file.state == 3 && httpStatus != 550) {            //__doPostBack('Content_UpdatePanel1', '');            setTimeout(__doPostBack('Content_UpdatePanel1', ''), 15000);            //setInterval(__doPostBack('Content_UpdatePanel1', ''), 60000);        }            }
}