Javascript events and creating a timer

Jan 15, 2009 at 8:37 PM
Hello -

I've written a custom adapter that lets us log things and uses ImageMagick for processing and image after upload, but I can't figure out how to capture a time stamp and pass it to my code behind when some clicks the Upload Button or in between files if there are multiples.

I've tried following the model of creating a fileStateChanged method and assigning to the JsFunc_FileStateChanged tag in the Uploader tag, but it only appears to catch the time once the file has actually transferred, so my start time is wrong.

Does anyone have a sample of how to do this?

Thanks in advance.

- Eric


Coordinator
Jan 15, 2009 at 11:12 PM
 The beginning of the file upload can be captured on the client with that code:

<
script>
function FileStateChanged(uploader, file, httpStatus, isLast){
    Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
    if(file.state == Flajaxian.File_Uploading){
        // file upload starts
    }
}
</script>
<fjx:FileUploader JsFunc_FileStateChanged="FileStateChanged" runat="server" >
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" />
    </Adapters>
</fjx:FileUploader>
Jan 15, 2009 at 11:21 PM
Will this fire for each file in a list?  It looks like ProcessFile in my custom adapter is called once per file object, so I can build a function to return a high res date time stamp in the //file upload starts bit and then pass it to my adapter?

Is there an elegant way to pass a variable for each invocation of the adapter?  Or should I do something like have a hidden label and set the value?


Coordinator
Jan 16, 2009 at 12:13 AM
Ont thing I can't understand is why you need to process the timestamp on the client? Can you trust the client? Why don't you define the timestamp on the server?
Jan 16, 2009 at 5:04 AM
Well, ideally I want to capture the timestamp for the instant the Upload button is captured, but also want to be able to get a timestamp for each file start if there are multiples in the upload.

If doing client side javascript is not the best way, I am willing to change this approach - I just didn't see how to capture the events in the code behind.  It would be easier to call a DateTime helper that I can format it for me since I log it in sqlserver.


Coordinator
Jan 16, 2009 at 5:06 PM
Ok I understand you want to measure from the upload start time time. The problem with that is that there is no way to make this safe because any hacker can tweak the client time very easily.

Better use the events on code behind like this:
<script runat="server">
protected void FileNameDetermining(object sender, FileNameDeterminingEventArgs args)
{
    // take your timestamp here
    // you can also change the file name here args.FileName
}
</script>
<fjx:FileUploader ID="FileUploader1" RequestAsPostBack="true" runat="server">
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" OnFileNameDetermining="FileNameDetermining" />
    </Adapters>
</fjx:FileUploader>
Jan 16, 2009 at 6:43 PM
Thanks - I will give that shot today and post back.