Adding State Variable to the Upload

Jul 2, 2009 at 1:28 PM

Hi,

Ive read a number of discussions on passing a state variable as well as tried your solutions.  If I use non-amazon file uploader adding state is no problem, however since amazon uploader does not allow RequestAsPostBack to be set to true, I have tried passing the state via javascript.  So far no luck.  Can you show just a very simple of example of this working?

 function FileStateChanged(uploader, file, httpStatus, isLast){

                        alert('state change');

                         <%= FileUploaderFlvAmazon.ClientID %>.setStateVariable("TestVar1", "TestState1");

  </script>

<fjx:FileUploader ID="FileUploaderFlvAmazon" JsFunc_FileStateChanged="FileStateChanged"   runat="server"  >

                        <Adapters>

                          <fjx:DirectAmazonUploader   ConfirmUploadJsFunc="ConfirmUploadJsFunc"  OnConfirmUpload="FileUploaderFlvAmazon_ConfirmUpload" 

                            AccessKey="WebConfig:AmazonAccessKey"

                            SecretKey="WebConfig:AmazonSecretKey"

                            BucketName="somebucket"/>

                        </Adapters>

                   </fjx:FileUploader>

 

--------------

 

As you click 'Upload' you would expect to see something inside the Request object

protected void Page_Load(object sender, EventArgs e)

{

        Debug.WriteLine("Passed value:" + this.Request.QueryString["TestVar1"];   // prints empty value

      // and if you do a forloop on the Request object, the expect 'TestVar1' doesnt exist

 

     // I have also tried adding the var on the server side just to see if it makes any difference

    //  FileUploaderFlvAmazon.State.Add(etc,etc)

}

 

 

------------------------

The control has been working fine thus far, and this is the last thing that I need to get going properly...

Thanks for your support.

Aug 17, 2009 at 12:22 AM

Hi wojouk,

Any luck on this?  I'm having a similar issue with the DirectAmazonUploader. 

I'm trying to store information into a database about the file that is being uploaded.  And I want to be able to catch errors and display an error message to the user.  for example, if there is an error inserting into the database, i want to cancel the upload and display an error message.  And I thought I could change a statevariable or I could change the  'HttpContext.Current.Response.StatusCode to a custom code to show an error.  But it seems both theses methods need a postback.  Any ideas?

Aug 24, 2009 at 3:57 PM

Hi kbende,

I never solved this particular problem...I tried a few things and eventually gave up - could not justify any more time on it since my users are internal company admins.

However, if you come across a solution, let me know as I certainly remember the frustrations on this one.

cheers.

 

Coordinator
Aug 24, 2009 at 6:45 PM

Please get the latest version from http://www.flajaxian.com/Downloads/DirectAmazonUploader1.0.aspx with the same key and you will be able to do that:

 

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.FileUploader" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.DirectAmazonUploader" %>
<script runat="server">
private void FileUploaderFlvAmazon_ConfirmUpload(object sender, ConfirmUploadEventArgs e)
{
    throw new ApplicationException("##" + e.Name + "##" +"Some error type" + "##");
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
    <script type="text/javascript">
    function ConfirmUploadJsFunc(r) {
        if (r.isError) alert("Error File: " + r.pageContent.split("##")[1].split("##").join("")+ "\n" + 
                             "Error Type: " + r.pageContent.split("##")[2].split("##").join(""));
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fjx:FileUploader ID="FileUploaderFlvAmazon" runat="server">
            <Adapters>
              <fjx:DirectAmazonUploader ConfirmUploadJsFunc="ConfirmUploadJsFunc" OnConfirmUpload="FileUploaderFlvAmazon_ConfirmUpload" 
                AccessKey="WebConfig:AmazonAccessKey"
                SecretKey="WebConfig:AmazonSecretKey"
                BucketName="somebucket"/>
            </Adapters>
       </fjx:FileUploader>
    </div>
    </form>
</body>
</html>

 

 

Aug 26, 2009 at 12:15 PM

Thanks for the reply, I will take a look at this within the next few days.

 

Aug 27, 2009 at 1:22 PM

Hi vladb,

I was able to get the code with working the latest version of the directuploader libraries.  But I wasn't able to throw an exception in the FileNameDeterming event.  When I throw the exception in the ConfirmUpload event, it works.  What's the reasoning behind that?

Coordinator
Aug 27, 2009 at 3:33 PM

In the example I use OnConfirmUpload

Aug 27, 2009 at 5:09 PM

Why can't I use the OnFileNameDetermining?

 

Coordinator
Aug 27, 2009 at 7:59 PM

Because OnFileNameDetermining is called on the initial ajax call before any file has been transfered. You should only use it to change file names, anything else should go to OnConfirmUpload otherwise you can't be sure that you will ever get there.

Use fiddler to see what and when is happening

Sep 5, 2009 at 6:38 PM

Thanks for the example, I was able to get that to work.  I throw an error and can parse it and display the message to the user the way you should me.  But when I upload 2 or more files that have errors, I can only retrieve the last file that had an error.  I see in fiddler both responses with errors, but in the ConfirmUploadJsFunc, I can only see the last error.  Is there any way to get all errors?

Also, if all files have been uploaded successfully, is there a way in ConfirmUploadJsFunc to loop through the response and show all filenames that have been uploaded successfully?

 

Thanks for the help.