Throwing errors in Custom Adapters

Nov 26, 2008 at 2:33 PM
I always wind up finding myself needing strange situations using this control... Maybe it's because I just love it so much.

My latest weirdness is that I'd like to use some additional logic inside a custom adapter. For instance, if a file already exists, I'd like to mark that particular file as a failure, and then retrieve that there was a problem with that file in my FileReceived handler. So the flow would be something like this

[customadapter]
public override void ProcessFile(HttpPostedFile file)
{
    if(fileexists)
    {
        error!
    }
    else
    {
        do stuff
    }
}

[codebehind for page]
protected void FileReceived(object sender, EventArgs e)
{
   if(therewasanerror)
   {
       handle stuff this way
   }
   else
    {
        process like normal.
    }
}

Any thoughts? Thanks in advance!

Coordinator
Nov 26, 2008 at 5:02 PM
Just read the documentation :)

http://www.flajaxian.com/Flajaxian.com/FileUploader2.0Help.html#HowToNotifyUser
Dec 1, 2008 at 6:52 PM
How can I know the index of the file being processed in a batch? For example, an old post here (http://www.codeplex.com/FlajaxianFileUpload/Thread/View.aspx?ThreadId=35734) refers to a .index property, but this no longer seems to be the case.

Also, how can I throw a status error from my custom upload adapter? I understand the client-side portion (for the most part) but I can't figure out how to create my own error conditions in the upload adapter.

So for example, I want to reject a file server-side based on the processing I'm doing in the custom adapter. I want to send that error to the javascript, and I want to count and reference the files so I can have some useful messages (x of y photos successfully updated), etc.

Thanks as always.
Dec 1, 2008 at 7:16 PM
Ok, so I think I can get an error thrown this way, but can I pass the text across to the javascript, or do I only know that there's been *an* error?

...inside the adapter:
if (!fileexists.Exists)
{
    file.SaveAs(String.Concat(fullpath, Path.DirectorySeparatorChar, file.FileName));
}
else
{
    throw new Exception("that there file done already be there.");
}

Still wondering about the indexing, though... Thanks!
Coordinator
Dec 1, 2008 at 7:31 PM
Edited Dec 1, 2008 at 7:33 PM
For the error why don't you do that:
http://www.flajaxian.com/Flajaxian.com/FileUploader2.0Help.html#HowToNotifyUser

I am not sure why you would need to know the index of the file? You have it's name. You can get the index as:

 <script>
function FileStateChanged(uploader, file, httpStatus, isLast){
    Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
    
    if(file.state > Flajaxian.File_Uploading){
        var index = -1;
        for(var i = 0; i < uploader.get_filesList().length; i++){
              if(uploader.get_filesList()[i].id == file.id){
                   index = i; break;
              }
        }
        alert(index);
    }
}
</script>
<div id="MyDiv"></div>
<fjx:FileUploader JsFunc_FileStateChanged="FileStateChanged" runat="server" >
    <Adapters>
        <fjx:FileSaverAdapter Runat="server" FolderName="UploadFolder" />
    </Adapters>
</fjx:FileUploader>
Coordinator
Dec 1, 2008 at 7:33 PM
Ah ok you are asking if you can transfer strings. No, you have to aggree on code=string pairs, then you can initiate them on the client. But transfering big strings back and forth is not a very good idea
Dec 3, 2008 at 3:59 PM
Your Javascript actually led to exactly what I need - the file.id property! I was not aware that property existed, and that's what I needed. Thank you. Maybe we can get an update to the documentation that lists all the client-side properties of the objects?

As for the error stuff, is the HTTP context able to be modified within an upload adapter? I'm content at this point to just throw a generic error and be  done with it, but perhaps in the future it would be nice to identify specific errors by doing as outlined in the docs, except from within the upload adapter itself rather than the code-behind.

Thanks again.
Coordinator
Dec 4, 2008 at 2:05 AM
I have updated the documentation at http://www.flajaxian.com/Flajaxian.com/FileUploader2.0Help.html#HowToUseClientSideEvents